1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[100][100]; 7 int main() 8 { 9 int m,n,i,j,x,y,k; 10 char s; 11 scanf("%d%d",&m,&n); 12 for(i=0;i<m;i++) 13 for(j=0;j<n;j++) 14 scanf("%d",&a[i][j]); 15 scanf("%d%d",&x,&y); 16 getchar(); 17 scanf("%c",&s); 18 scanf("%d",&k); 19 while(k--) 20 { 21 if(a[x][y]==1) 22 { 23 a[x][y]=0; 24 if(s==‘U‘) 25 { 26 y=y+1; 27 s=‘R‘; 28 continue; 29 } 30 if(s==‘D‘) 31 { 32 y=y-1; 33 s=‘L‘; 34 continue; 35 } 36 if(s==‘L‘) 37 { 38 x=x-1; 39 s=‘U‘; 40 continue; 41 } 42 if(s==‘R‘) 43 { 44 x=x+1; 45 s=‘D‘; 46 continue; 47 } 48 } 49 if(a[x][y]==0) 50 { 51 a[x][y]=1; 52 if(s==‘U‘) 53 { 54 y=y-1; 55 s=‘L‘; 56 continue; 57 } 58 if(s==‘D‘) 59 { 60 y=y+1; 61 s=‘R‘; 62 continue; 63 } 64 if(s==‘L‘) 65 { 66 x=x+1; 67 s=‘D‘; 68 continue; 69 } 70 if(s==‘R‘) 71 { 72 x=x-1; 73 s=‘U‘; 74 continue; 75 } 76 } 77 } 78 printf("%d %d\n",x,y); 79 return 0; 80 }
原文:http://www.cnblogs.com/cancangood/p/4361052.html