标签:历届试题 兰顿蚂蚁
#include<cstdio> #include<cstdlib> #include<cstring> using namespace std; int map[110][110],k,m,n,s; void DFS(int x,int y,char ch){ if(s==k){ printf("%d %d\n",x,y); return ; } if(map[x][y]==1){ if(ch=='U'){ ch='R';s++; map[x][y]=0; DFS(x,y+1,ch); } else if(ch=='D'){ ch='L';s++; map[x][y]=0; DFS(x,y-1,ch); } else if(ch=='L'){ ch='U';s++; map[x][y]=0; DFS(x-1,y,ch); } else if(ch=='R'){ ch='D';s++; map[x][y]=0; DFS(x+1,y,ch); } } else { if(ch=='U'){ ch='L';s++; map[x][y]=1; DFS(x,y-1,ch); } else if(ch=='D'){ ch='R';s++; map[x][y]=1; DFS(x,y+1,ch); } else if(ch=='L'){ ch='D';s++; map[x][y]=1; DFS(x+1,y,ch); } else if(ch=='R'){ ch='U';s++; map[x][y]=1; DFS(x-1,y,ch); } } } int main() { int i,j,x,y; char ch; scanf("%d%d",&m,&n); for(i=0;i<m;++i){ for(j=0;j<n;++j) scanf("%d",&map[i][j]); }s=0; scanf("%d %d %c %d",&x,&y,&ch,&k); DFS(x,y,ch); return 0; }
标签:历届试题 兰顿蚂蚁
原文地址:http://blog.csdn.net/r1986799047/article/details/43882703