zoukankan      html  css  js  c++  java
  • 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): 55194    Accepted Submission(s): 14895

    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
     
    思路:DFS + 剪枝
     
    代码:

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cmath>

    using namespace std;

    int hash[8][8];

    char map[8][8];

    int move[4][2] = {1,0,-1,0,0,1,0,-1};

    int n,m,t; int sx,sy,dx,dy;

    int flag;

    void DFS(int ax,int ay,int step)

    {    

    if(ax == dx && ay == dy)    

    {        

    if(step == t)           

      flag = 1;        

    return ;    

    }  

       if(step >= t)      

    return ;   

      if(flag)      

    return ;    

    for(int i = 0;i < 4;i ++)  

       {        

    int x = ax + move[i][0];int y  = ay + move[i][1];      

       if(map[x][y] != 'X' && hash[x][y] == 0 && x >= 1 && x <= n         && y <= m && y >= 1)        

    {            

    hash[x][y] = 1;            

    DFS(x,y,step + 1);            

    hash[x][y] = 0;            

    if(flag)               

    return ;        

    }    

    }

    }

    int main()

    {    

    while(scanf("%d%d%d",&n,&m,&t),n != 0 && m != 0 && t != 0)    

    {        

    memset(hash,0,sizeof(hash));        

    flag = 0;        

    for(int i = 1;i <= n;i ++)       

         for(int j = 1;j <= m;j ++)         

       {             

       scanf(" %c",&map[i][j]);      

              if(map[i][j] == 'S')               

    {                   

      sx = i;sy = j;                

         hash[i][j] = 1;           

         }             

       if(map[i][j] == 'D')          

          {                  

       dx = i;dy = j;           

         }            }     

       if(abs(dx - sx) + abs(dy - sy) > t || (sx + sy + dx + dy + t) % 2 == 1)     

       {             printf("NO ");        

         continue;        }      

      else      

      {             DFS(sx,sy,0);   

      

            if(flag == 0)            

        printf("NO ");           

      else               

    printf("YES ");    

        }    

    }    

    return 0;

    }

      

  • 相关阅读:
    文章索引
    Rancher pipeline 实现简单跟踪
    rancher 应用商店
    nginx ingress 在aks 上安装
    go countdown
    go channel pipeline 套路
    gorm使用
    华为云cce pvc 指定云硬盘云存储
    influxdb 基本概念
    Python3处理xlsx去掉含有特定字符的行
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3286449.html
Copyright © 2011-2022 走看看