• hdu 1010 Tempter of the Bone


    Tempter of the Bone

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 129140    Accepted Submission(s): 34882


    Problem Description
    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
     
     
    题意:走迷宫   看你是不是可以走出去
    直接dfs     bfs   都可以过的 
    我使用的是dfs
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 int h[4][2]={1,0,0,1,-1,0,0,-1};
     8 char mp[10][10];
     9 int vis[10][10];
    10 int lag,t;
    11     int n,m;
    12 void dfs(int i,int j,int time)
    13 {
    14 
    15     if(lag||i<0||i>n||j<0||j>m||time>t)
    16     return ;
    17     for(int k=0;k<4;k++)
    18     {
    19         int di=i+h[k][0];
    20         int dj=j+h[k][1];
    21         if(vis[di][dj]==0&&mp[di][dj]=='.')
    22         {
    23             vis[di][dj]=1;
    24             dfs(di,dj,time+1);
    25             vis[di][dj]=0;
    26         }
    27          if(vis[di][dj]==0&&mp[di][dj]=='D'&&time==t)
    28         {
    29             lag=1;
    30             return ;
    31         }
    32     }
    33 }
    34 int main()
    35 {
    36 
    37     while(~scanf("%d%d%d",&n,&m,&t)&&n&&m&&t)
    38     {
    39         memset(vis,0,sizeof(vis));
    40         lag=0;
    41         //getchar();
    42         for(int i=0; i<n; i++)
    43         {
    44             getchar();
    45             scanf("%s",mp[i]);
    46         }
    47         int x,y,dx,dy;
    48         for(int i=0; i<n; i++)
    49         {
    50             for(int j=0; j<m; j++)
    51             {
    52                 if(mp[i][j]=='S')
    53                 {
    54                     x=i;
    55                     y=j;
    56                 }
    57                 if(mp[i][j]=='D')
    58                 {
    59                     dx=i;
    60                     dy=j;
    61                 }
    62             }
    63         }
    64         if(abs(dx-x)+abs(dy-y)>t||(abs(dx-x)+abs(dy-y)+t)%2);
    65         else{
    66          vis[x][y]=1;
    67         dfs(x,y,1);
    68         }
    69 
    70         if(!lag)
    71         printf("NO
    ");
    72         else
    73         printf("YES
    ");
    74     }
    75     return 0;
    76 }
  • 相关阅读:
    Nginx如何配置基础缓存
    Websocket消息过长自动断开连接?
    Docker错误删除Postgresql容器如何恢复?
    Docker安装带中文全文搜索插件zhparser的Postgresql数据库
    Postgresql数据库安装中文全文搜索插件zhparser的问题
    Presto通过RESTful接口新增Connector
    在windows的IDEA运行Presto
    Druid.io通过NiFi摄取流数据
    Druid.io SQL乱码问题
    Druid.io启用SQL支持
  • 原文地址:https://www.cnblogs.com/52why/p/7478114.html
Copyright © 2020-2023  润新知