zoukankan      html  css  js  c++  java
  • Tempter of the Bone

    The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze. 

    The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him. 

    Input

      The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following: 

    'X': a block of wall, which the doggie cannot enter; 
    'S': the start point of the doggie; 
    'D': the Door; or 
    '.': an empty block. 

    The input is terminated with three 0's. This test case is not to be processed. 
    Output

       For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise. 
    Sample Input

    4 4 5
    S.X.
    ..X.
    ..XD
    ....
    3 4 5
    S.X.
    ..X.
    ...D
    0 0 0

    Sample Output

    NO
    YES
    代码:
    数据都对,但是没通过..就这思路吧
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<queue>
     4 #include<algorithm>
     5 using namespace std;
     6 struct xy
     7 {int x,y,step;
     8     
     9 }pr,ne;
    10 int n,m,t,stx,sty,enddx,enddy;
    11 char a[7][7];
    12 int v[7][7];
    13 int fx[4]={0,0,1,-1},fy[4]={1,-1,0,0};
    14 int bfs()
    15 {pr.x=stx;
    16  pr.y=sty;
    17  pr.step=0;
    18  memset(v,0,sizeof(v));
    19  v[stx][sty]=1;
    20  queue<xy>q;
    21  q.push(pr);
    22  while(!q.empty())
    23     {pr=q.front();
    24      q.pop();
    25      for(int i=0;i<4;i++)
    26        {ne.x=pr.x+fx[i];
    27         ne.y=pr.y+fy[i];
    28         ne.step=pr.step+1;
    29         if(!(ne.x>=0&&ne.y>=0&&ne.x<n&&ne.y<m&&!v[ne.x][ne.y]&&a[ne.x][ne.y]!='X'))
    30              continue;
    31             if(ne.x==enddx&&ne.y==enddy)
    32             {return ne.step;
    33                 
    34              }
    35          q.push(ne);      
    36          v[ne.x][ne.y]=1;
    37               
    38        }    
    39     }
    40  return -1;    
    41 }
    42 int main()
    43 {
    44     while(~scanf("%d %d %d",&n,&m,&t)&&(n||m||t))
    45     {for(int i=0;i<n;i++)
    46        scanf("%s",a[i]);
    47      for(int i=0;i<n;i++)
    48        for(int j=0;j<m;j++)
    49          {if(a[i][j]=='S')
    50             {stx=i;
    51              sty=j;
    52                 
    53             }
    54           if(a[i][j]=='D')
    55             {enddx=i;
    56              enddy=j;
    57                 
    58             }
    59                   
    60              
    61          } 
    62      if(bfs()<=t&&bfs()>=0) printf("YES
    ");
    63      else printf("NO
    ");      
    64         
    65     }
    66     return 0;
    67 }
  • 相关阅读:
    paip.Answer 3.0 注册功能SQL注入漏洞解决方案
    paip.PHPasp—jsp实现事件机制 WEBFORM式开发
    paip.SQL特殊字符转义字符处理
    paip.提升效率更改数组LIST对象值for与FOREACH
    paip.提升效率源码生成流程图工具
    paip.提升安全性动态KEY
    paip.regf文件读取与编辑
    paip.提升开发效率终极方法组件化及其障碍
    提升安全性用户资金防篡改
    paip.提升安全性360,WI,AWVS三款WEB程序安全检测软件使用总结
  • 原文地址:https://www.cnblogs.com/hss-521/p/7270346.html
Copyright © 2011-2022 走看看