1 solutions
-
1
#include<iostream> using namespace std; const int N=1e2+7; int n; int sx,sy,ex,ey; char ma[N][N]; int dx[130],dy[130]; string s; string strs[]={"0","I get there!","I have no idea!","I am dizzy!","I am out!"}; int len; int flag; void dfs(int x,int y,int u){ if(flag)return ; if(x==ex&&y==ey){ flag=1; return ; } if(ma[x][y]=='#'){ flag=3; return ; } if(x<1||x>n||y<1||y>n){ flag=4; return ; } if(u==len){ flag=2; return ; } int xx=x+dx[s[u]]; int yy=y+dy[s[u]]; dfs(xx,yy,u+1); } int main(){ dx['U']=-1,dx['D']=1; dy['L']=-1,dy['R']=1; int t; cin>>t; while(t--){ cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ cin>>ma[i][j]; if(ma[i][j]=='S') sx=i,sy=j; if(ma[i][j]=='T') ex=i,ey=j; } int q; cin>>q; while(q--){ flag=0; cin>>s; len=s.length(); dfs(sx,sy,0); cout<<strs[flag]<<endl; } } return 0; } /* 2 2 S. #T 2 RD DR 3 S.# .#. .T# 3 RL DDD DDRR */
- 1
Information
- ID
- 1595
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By