• hdu 1010 Tempter of the Bone (DFS)


    Tempter of the Bone

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


    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
     
    Author
    ZHANG, Zheng
     
    Source
     
    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1072 1026 1175 1258 1180 
     
     1 //62MS    232K    1306 B    G++    
     2 /*
     3 
     4     题意:
     5         给出一个图,求点S到点D是否存在步数为K的路径
     6         
     7     DFS:
     8         不剪枝的话复杂度约为 4^49 必TLE
     9         此处最重要的剪枝是奇偶剪枝,所谓奇偶剪枝,
    10     就是判断剩余步数与目标的最短路径是否符合要求,不符合则先排除
    11     从而优化。 
    12 
    13 */
    14 #include<stdio.h>
    15 #include<string.h>
    16 #define N 15
    17 char g[N][N];
    18 int vis[N][N];
    19 int mov[4][2]={0,1,1,0,0,-1,-1,0};
    20 int n,m,k,flag;
    21 int ex,ey;
    22 int Abs(int a)
    23 {
    24     return a>0?a:-a;
    25 }
    26 void dfs(int x,int y,int cnt)
    27 {
    28     if(flag || cnt>k) return;
    29     if(g[x][y]=='D' && cnt==k) flag=1; 
    30     int temp=(k-cnt)-Abs(x-ex)-Abs(y-ey);
    31     if(temp<0 || temp&1) return;
    32     for(int i=0;i<4;i++){
    33         int x0=x+mov[i][0];
    34         int y0=y+mov[i][1];
    35         if(x0>=0 && x0<n && y0>=0 && y0<m && !vis[x0][y0] && g[x0][y0]!='X'){
    36             vis[x0][y0]=1;
    37             dfs(x0,y0,cnt+1);
    38             vis[x0][y0]=0;
    39         }
    40     }
    41 }
    42 int main(void)
    43 {
    44     int sx,sy;
    45     while(scanf("%d%d%d",&n,&m,&k),n+m+k)
    46     {
    47         int cnt=1;
    48         for(int i=0;i<n;i++){
    49             scanf("%s",g[i]);
    50             for(int j=0;j<m;j++)
    51                 if(g[i][j]=='S') 
    52                     sx=i,sy=j;
    53                 else if(g[i][j]=='.') cnt++;
    54                 else if(g[i][j]=='D')
    55                     ex=i,ey=j;
    56         }
    57         if(cnt<k){
    58             puts("NO");
    59             continue;
    60         }
    61         memset(vis,0,sizeof(vis));
    62         vis[sx][sy]=1;
    63         flag=0;
    64         dfs(sx,sy,0);
    65         if(flag) puts("YES");
    66         else puts("NO"); 
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    浮窗显示到毫秒时间的小工具 各大电商平台的时间
    非常不错的电脑截图软件介绍—截图加贴图。
    ​Everything 文件搜索神器 基于名称实时定位文件和目录
    THUPC2021初赛 & ICPC上海站游记
    旧题重做
    常用思想方法——数学期望篇
    vim 常用操作技巧
    生物制图软件——CirCos在Linux服务器上安装步骤:
    vue-element-admin 改造
    vue
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3474686.html
Copyright © 2020-2023  润新知