隊內訓練題 9_15_2012 D. Maze

D. Maze

 

The robot is trapped in maze! The maze consists of four kinds of grids:

    -    ,.' means blank ground, the robot can get through it

    -    ,#' means block, the robot can't get through it

    -    ,S'indicates where the robot is.

    -    ,T'indicates where the robot aims to.

Now we send some command to the robot,  ,LRUD'represent that the robot make one move to left, right, up or down respectively. Help us to report the state of the robot.

 

Input

The first line contains a single integer T, indicating the number of test cases.

Each test case begins with one integer N (1 <= N <= 50), indicating the size of the maze. The followed N lines are N strings whose length is also N, indicating the maze. The following is an integer Q (1 <= Q <= 100), indicating the number of queries. The followed Q lines are Q strings contain only ,LRUD', indicating the commands, whose lengths are less than 1000.

 

Output

For each query, output a single line:

I get there!  if the robot can reach the destination after executing the command, you should notice reaching the destination before the command ends is also included in this situation.

I have no idea!  If the robot stil couldn't reach the destination after executing the command.

I am dizzy!  if the robot was knocked by the block while executing the command.

I am out!  if the robot was out of the boundary while executing the command.

 

Sample Input

Sample Output

2

2

S.

#T

2

RD

DR

3

S.#

.#.

.T#

3

RL

DDD

DDRR

I get there!

I am dizzy!

I have no idea!

I am out!

I get there!

 

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
    char a[55][55];
    int turn,n,m,p,q;
    int sx,sy,tem;
    string str;
    cin>>turn;
    while(turn--){
        memset(a,'*',sizeof(a));
        cin>>n;
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++ ){
                cin>>a[i][j];
                if(a[i][j]=='S'){sx=i;p=i;sy=j;q=j;}
            }
        cin>>m;
        while(m--){
             cin>>str; 
             tem=str.length();//cout<<"  $$$"<<tem<<endl;
             
             int i; 
             sx=p;sy=q;          
             for(i=0; i<tem;i++){
                 if(str[i]=='R'){
                     sy++;
                     if(a[sx][sy]=='.');
                     if(a[sx][sy]=='#'){printf("I am dizzy!\n");break;};
                     if(a[sx][sy]=='*'){printf("I am out!\n");break;};
                     if(a[sx][sy]=='T'){printf("I get there!\n");break;};
                 }
                 if(str[i]=='L'){
                     sy--;
                     if(a[sx][sy]=='.');
                     if(a[sx][sy]=='#'){printf("I am dizzy!\n");break;};
                     if(a[sx][sy]=='*'){printf("I am out!\n");break;};
                     if(a[sx][sy]=='T'){printf("I get there!\n");break;};
                 }
                 if(str[i]=='D'){
                     sx++;
                     if(a[sx][sy]=='.');
                     if(a[sx][sy]=='#'){printf("I am dizzy!\n");break;};
                     if(a[sx][sy]=='*'){printf("I am out!\n");break;};
                     if(a[sx][sy]=='T'){printf("I get there!\n");break;};
                 }
                 if(str[i]=='U'){
                     sx--;
                     if(a[sx][sy]=='.');
                     if(a[sx][sy]=='#'){printf("I am dizzy!\n");break;};
                     if(a[sx][sy]=='*'){printf("I am out!\n");break;};
                     if(a[sx][sy]=='T'){printf("I get there!\n");break;};
                 }
              } //cout<<"i="<<i<<"tem"<<tem<<"a[][]"<<a[sx][sy]<<endl;
              if(i==tem && (a[sx][sy]=='.' || a[sx][sy]=='S'))printf("I have no idea!\n");  
        }
    }    
    return 0;
}


转载于:https://my.oschina.net/dianpaopao/blog/78721

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值