poj 1573 Robot Motion
2012-02-26 22:14
232 查看
http://poj.org/problem?id=1573
简单的搜索题就不说了;因为"whether or not the number before it is 1"wrong了两次;啊!!
代码:
View Code
简单的搜索题就不说了;因为"whether or not the number before it is 1"wrong了两次;啊!!
代码:
View Code
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; bool ok = 0; void print1(int n) { printf("%d step(s) to exit\n",n); ok = 1; } void print2(int a,int b) { printf("%d step(s) before a loop of %d step(s)\n",b - 1,a - b +1); ok =1; } int main() { int y = 0; int x = 0; int sta = 0; char s[15][15] ={NULL}; int visit[20][20] = {0}; int a = 0; int b = 0; while(scanf("%d%d%d",&y,&x,&sta),x&&y&&sta) { ok = 0; memset(visit,0,sizeof(visit)); a = y; b = sta; visit[a][b] = 1; for(int i = y; i >= 1; --i) scanf("%s",s[i]+1); while(1) { switch(s[a][b]) { case 'E':{if(b+1 > x) print1(visit[a][b]); else if(visit[a][b+1]) print2(visit[a][b],visit[a][b+1]); else {visit[a][b+1] = visit[a][b] +1;b++;}}break; case 'W':{if(b-1 < 1) print1(visit[a][b]); else if(visit[a][b-1]) print2(visit[a][b],visit[a][b-1]); else {visit[a][b-1] = visit[a][b] +1;b--;}}break; case 'N':{if(a+1 > y) print1(visit[a][b]); else if(visit[a+1][b]) print2(visit[a][b],visit[a+1][b]); else {visit[a+1][b] = visit[a][b] +1;a++;}}break; case 'S':{if(a-1 < 1) print1(visit[a][b]); else if(visit[a-1][b]) print2(visit[a][b],visit[a-1][b]); else {visit[a-1][b] = visit[a][b] +1;a--;}}break; } if(ok) break; } } return 0; }
相关文章推荐
- Poj OpenJudge 百练 1573 Robot Motion
- POJ 1573 Robot Motion (模拟+不回溯的dfs 水题)
- POJ 刷题系列:1573. Robot Motion
- POJ 1573 Robot Motion(模拟)
- POJ 1573 Robot Motion(BFS)
- POJ 1573 Robot Motion(BFS)
- Robot Motion - poj 1573
- poj 1573 Robot Motion
- poj 1573 Robot Motion_模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573, Robot Motion
- poj 1573 - Robot Motion(BFS递推)
- poj 1573 Robot Motion
- poj 1573 Robot Motion
- POJ 1573 Robot Motion 模拟
- poj 1573 Robot Motion_模拟
- poj 1573 Robot Motion 模拟
- POJ 1573-Robot Motion
- poj 1573 Robot Motion
- poj 1573 Robot Motion