Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
又是一水?#include <iostream> #include <cstring> #include <stdio.h> #include <stdlib.h> #include <cmath> #include <algorithm> using namespace std; int main() { while(1){ int x,y,e; char instr[15][15]; scanf("%d%d%d",&x,&y,&e); if(!x) break; for(int i = 1; i <= x; i++){ char tmp[233]; scanf("%s", tmp); for(int j = 1; j <= y; j++){ instr[i][j] = tmp[j-1]; } } int cnt = 0; int X = 1, Y = e; int sx[15][15]; for(int i = 1; i <= x; i++){ for(int j = 1; j <= y; j++){ sx[i][j] = -1; } } while(1){ if(X==0 || Y==0 || X==x+1 || Y==y+1){ printf("%d step(s) to exit\n", cnt); break; } if(sx[X][Y] != -1){ printf("%d step(s) before a loop of %d step(s)\n", sx[X][Y], cnt-sx[X][Y]); break; } sx[X][Y] = cnt; cnt++; switch(instr[X][Y]){ case 'N': X--; break; case 'S': X++; break; case 'W': Y--; break; case 'E': Y++; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator