8B - Obsession with Robots
来源:互联网 发布:护眼有什么软件 编辑:程序博客网 时间:2024/06/07 13:10
题目给出一个机器人在某个迷宫中走的路线,问这个路线是否可能是起点到终点的最短路径
如果某路径是迷宫的最短路径
1,经过的位置最多只出现一次 (bfs求最短路的标记的原因)
2,刚走到某个位置时,这个位置只能由刚经过的位置到达(如果这个位置旁边的某位置早已经到达过,那么如果之前从那个位置走到这个位置,最终的路径肯定会更短)
然后分情况讨论即可
#include<cstdio>#include<cstring>#include<map>using namespace std;int gra[105*2][105*2];struct node{int a,b;}x[4]={{0,1},{0,-1},{1,0},{-1,0}};map<char,int> vis;bool judge(int a,int b)//判断是否有重复 {int cnt=0;for(int i=0;i<4;++i){int tx=a+x[i].a,ty=b+x[i].b;if(gra[tx][ty])//旁边走过的路只能有一个 {++cnt;if(cnt>1){return 1; } }}return 0;}bool slove(char s[]){int sx=105,sy=105,len=strlen(s);gra[sx][sy]=1;for(int i=0;i<len;++i){int tp=vis[s[i]];sx+=x[tp].a;sy+=x[tp].b;if(gra[sx][sy]||judge(sx,sy)){return 0;}gra[sx][sy]=1;}return 1;}int main(){vis['L']=0;vis['R']=1;vis['U']=2;vis['D']=3;char s[105]={0};scanf("%s",s);printf("%s\n",slove(s)?"OK":"BUG");return 0;}
0 0
- 8B - Obsession with Robots
- CodeForces 8B - Obsession with Robots
- cf B. Obsession with Robots 判断最短路?
- Codeforces 8B Obsession With Robot 简单图遍历
- B - Game of Robots
- B. Game of Robots
- Codeforces 606B Testing Robots 【模拟】
- CodeForces 606 B. Testing Robots(水~)
- codeforces 670B Game of Robots
- codeforces 670B Game of Robots
- codeforcs 350 B. Game of Robots
- CodeForces 670B Game of Robots
- Codeforces 606 B Testing Robots【模拟】
- CodeForces 606B Testing Robots【读题题QAQ】
- 随心所“语”之 3B大战:robots协议问题
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
- Codeforces Round #335 (Div. 2) B.Testing Robots
- 构造函数语义学
- xshell或putty上 按小键盘上的数字键并不能输入数字的解决办法
- JavaScript 中一些值的比较,熟悉规范
- spark:kmeans测试
- Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRID
- 8B - Obsession with Robots
- Android中ProgressBar自定义进度条的高度、颜色、圆角
- jQueryUI中Datepicker(日历)插件的介绍和使用
- 在Activiti中使用UUID作为主键生成策略
- UITextField的字体和颜色和文字显示位子。
- shell脚本输出颜色字体
- HDU1062 Text Reverse
- 构造方法
- 高性能服务器程序框架