标签:des style class blog code http
题目链接:
http://poj.org/problem?id=1573
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10202 | Accepted: 4971 |
Description
Input
Output
Sample Input
3 6 5 NEESWE WWWESS SNWWWW 4 5 1 SESWE EESNW NWEEN EWSEN 0 0 0
Sample Output
10 step(s) to exit 3 step(s) before a loop of 8 step(s)
Source
代码为:
#include<cstdio> #include<cstring> const int maxn=10+10; char map[maxn][maxn]; bool vis[maxn][maxn]; int step[maxn][maxn]; int row,colume,start; int ex,ey; int check(int x,int y) { if(x>=1&&x<=row&&y>=1&&y<=colume) return 1; return 0; } int main() { char str[maxn]; int currentx,currenty,pos,ans; ind:while(scanf("%d%d%d",&row,&colume,&start)!=EOF) { pos=0; ans=1; memset(step,0,sizeof(step)); memset(vis,false,sizeof(vis)); if(row==0&&colume==0&&start==0) return 0; for(int i=1;i<=row;i++) { scanf("%s",str); for(int j=1;j<=colume;j++) map[i][j]=str[j-1]; } currentx=1; currenty=start; while(!vis[currentx][currenty]) { if(!check(currentx,currenty)) { printf("%d step(s) to exit\n",ans); goto ind; } vis[currentx][currenty]=true; if(map[currentx][currenty]=='E') { if(currentx==1&¤ty==start) step[1][currenty]=0; else { pos++; ans++; step[currentx][currenty]=pos; } currentx=currentx; currenty=currenty+1; } else if(map[currentx][currenty]=='S') { if(currentx==1&¤ty==start) step[1][currenty]=0; else {pos++; ans++; step[currentx][currenty]=pos; } currentx=currentx+1; currenty=currenty; } else if(map[currentx][currenty]=='W') { if(currentx==1&¤ty==start) step[1][currenty]=0; else { pos++; step[currentx][currenty]=pos; ans++; } currentx=currentx; currenty=currenty-1; } else { if(currentx==1&¤ty==start) step[1][currenty]=0; else { pos++; step[currentx][currenty]=pos; ans++; } currentx=currentx-1; currenty=currenty; } } printf("%d step(s) before a loop of %d step(s)\n",step[currentx][currenty],ans-step[currentx][currenty]); goto ind; } return 0; }
poj1573 Robot Motion,布布扣,bubuko.com
标签:des style class blog code http
原文地址:http://blog.csdn.net/u014303647/article/details/30226557