1 solutions
-
0
C++ :
#include<iostream> #include<string> #include<cstring> using namespace std; bool vis[10][10]; string tab[10]; int nex[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; int end_x,end_y,n,m,t; bool dfs(int x,int y,int count) { if(end_x==x&&end_y==y&&count==t) return true; for(int i=0;i<4;i++) { int xx=x+nex[i][0],yy=y+nex[i][1]; if(xx>=0&&yy>=0&&xx<m&&yy<n&&tab[yy][xx]!='X'&&!vis[yy][xx]) { vis[yy][xx]=true; if(dfs(xx,yy,count+1)) return true; vis[yy][xx]=false; } } return false; } int main() { while(cin>>n>>m>>t,n||m||t) { int x,y; for(int i=0;i<n;i++) { cin>>tab[i]; for(int j=0;j<m;j++) if(tab[i][j]=='S') { x=j;y=i; } else if(tab[i][j]=='D') { end_x=j;end_y=i; } } //cout<<"b_x="<<x<<" b_y="<<y<<" end_x"<<end_x<<" end_y="<<end_y<<endl; memset(vis,false,sizeof(vis)); vis[y][x]=true; dfs(x,y,0)?cout<<"Get it!\n":cout<<"Change it!"<<endl; } return 0; }
- 1
Information
- ID
- 20204
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By