Codeforces 8B
2015-10-09 19:44
316 查看
题目大意:给出机器人的移动路线,求是否存在这样一个只有空格和障碍的棋盘,使得机器人从起点道中点的路径为最短路。
题解:开数组判断一下子,判断是否机器人走到的当前格子的相邻三个格子(除去来的那一个格子)中有一个被走过,如果有说明是不可行的。
%%%__debug\%\%\%\_\_debug
题解:开数组判断一下子,判断是否机器人走到的当前格子的相邻三个格子(除去来的那一个格子)中有一个被走过,如果有说明是不可行的。
%%%__debug\%\%\%\_\_debug
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<string> #define DEBUG(...) fprintf(stderr,__VA_ARGS__) using namespace std; const int MAXL=502; string s; bool vis[MAXL][MAXL]; int main() { #ifndef ONLINE_JUDGE freopen("8B.in","r",stdin); freopen("8B.out","w",stdout); #endif cin>>s; int x=250,y=250; vis[x][y]=1; for(int i=0;i<s.size();i++) { char c=s[i]; if(c=='L') x-=1; else if(c=='R') x+=1; else if(c=='U') y+=1; else y-=1; DEBUG("%d %d\n",x,y); if(vis[x][y]==1) { printf("BUG\n"); return 0; } else if(c=='R'&&(vis[x+1][y]==1||vis[x][y+1]==1||vis[x][y-1]==1)) { printf("BUG\n"); return 0; } else if(c=='L'&&(vis[x-1][y]==1||vis[x][y+1]==1||vis[x][y-1]==1)) { printf("BUG\n"); return 0; } else if(c=='D'&&(vis[x-1][y]==1||vis[x+1][y]==1||vis[x][y-1]==1)) { printf("BUG\n"); return 0; } else if(c=='U'&&(vis[x-1][y]==1||vis[x][y+1]==1||vis[x+1][y]==1)) { printf("BUG\n"); return 0; } vis[x][y]=1; } printf("OK\n"); }
相关文章推荐
- POJ 1010 STAMPS(dfs)
- ActionBar之自定义分享
- 【work】判断ip地址是否合法
- 重启docker服务器后 遇到 'device or resource busy'错误
- 启动fiddler8888被占用
- [Leetcode]Sum Root to Leaf Numbers
- error LNK2019: 无法解析的外部符号
- 用python3写一个华工SCUT连接的脚本
- ios之viewWithTag
- css 3d效果
- 依赖,关联
- Socket/Epoll主要流程对socket错误码正确处理
- 华为某年的一个机考题:计算最后一个出列者的编号
- codevs1183 泥泞的道路
- Redis阻塞队列原理学习
- linux curl 命令详解,以及实例
- 记录优秀博客
- servlet3.0
- 利用DisplayMetrics类获取Android设备屏幕分辨率
- 第四周实践项目6--多项式求和