Codeforces 8B
来源:互联网 发布:淘宝女装服装店铺简介 编辑:程序博客网 时间:2024/06/07 03:32
题目大意:给出机器人的移动路线,求是否存在这样一个只有空格和障碍的棋盘,使得机器人从起点道中点的路径为最短路。
题解:开数组判断一下子,判断是否机器人走到的当前格子的相邻三个格子(除去来的那一个格子)中有一个被走过,如果有说明是不可行的。
#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");}
0 0
- Codeforces 8B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- Codeforces Educational Codeforces Round 8 B. New Skateboard
- CodeForces 8B - Obsession with Robots
- Educational Codeforces Round 8 (A B C)
- Educational Codeforces Round 8-B. New Skateboard
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- ffmpeg SDK开发手册
- 重启docker服务器后 遇到 'device or resource busy'错误
- Android RecyclerView
- 【work】判断ip地址是否合法
- Flex工程部署到Tomcat的步骤
- Codeforces 8B
- POJ 1010 STAMPS(dfs)
- 递归与非递归实现走迷宫算法
- NYOJ 488 素数环 (深搜DFS)
- HDU 1556 Color the ball【线段树及lazy思想】【树状数组】
- 使用绞车和3PS滑轮计数器收放klein3000托鱼
- HDU3068最长回文 Manacher算法
- Python中unicode编码的字符串和其他格式的字符串之间进行转换
- Python Scapy(2.3.1)文档学习(四):高级用法