zoukankan      html  css  js  c++  java
  • HDU 1010 Temper of the bone(深搜+剪枝)

                  Tempter of the Bone

    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
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<stdlib.h>
     4 using namespace std;
     5 
     6 int a,b;
     7 bool flag;
     8 int start_x,start_y,end_x,end_y;
     9 int d[4][2]={0,1,1,0,0,-1,-1,0};
    10 char map[10][10];
    11 
    12 void DFS(int x,int y,int t)
    13 {
    14     int i;
    15     if(flag==true) return;
    16     if(t<abs(end_x-x)+abs(end_y-y)||(t-abs(end_x-x)+abs(end_y-y))%2) return;
    17     else if(t==0)
    18     {
    19         if(x==end_x&&y==end_y)
    20         {
    21             flag=true;
    22             return;
    23         }
    24         else return;
    25     }
    26     else
    27     {
    28         for(i=0;i<4;i++)
    29         {
    30             int nx=x+d[i][0],ny=y+d[i][1];
    31             if(nx>=0&&nx<a&&ny>=0&&ny<b&&(map[nx][ny]=='.'||map[nx][ny]=='D'))
    32             {
    33                 map[nx][ny]='X';
    34                 DFS(nx,ny,t-1);
    35                 map[nx][ny]='.';
    36             }
    37         }
    38         return;
    39     }
    40 }
    41 
    42 int main()
    43 {
    44     int i,j,t;
    45     while(cin>>a>>b>>t&&(a||b||t))
    46     {
    47         for(i=0;i<a;i++)
    48         cin>>map[i];
    49         for(i=0;i<a;i++)
    50         for(j=0;j<b;j++)
    51         {
    52             if(map[i][j]=='S')
    53             {
    54                 start_x=i;
    55                 start_y=j;    
    56             }
    57             else if(map[i][j]=='D')
    58             {
    59                 end_x=i;
    60                 end_y=j;
    61             }
    62             else continue;
    63         }
    64         flag=false;
    65         DFS(start_x,start_y,t);    
    66         if(flag==false)cout<<"NO"<<endl;
    67         else cout<<"YES"<<endl;
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    博弈最高位POJ 1704(Georgia and BobNim博弈)
    图片优化ios学习之真机测试 copy图片错误解决方案
    输入左移校草计划(Nim)
    类型函数C语言void关键字
    图层设置GDAL/OGR创建DXF文件中多图层的方法
    浏览器下载Firefox os 模拟器安装教程步骤详解
    工程图标ios学习之给程序设置logo
    实例收藏Android开发环境搭建和Android开发基础知识汇总值得收藏
    乱码插入mac mysql汉字乱码问题解决
    菜菜从零学习WCF一(WCF概述)
  • 原文地址:https://www.cnblogs.com/homura/p/4668740.html
Copyright © 2011-2022 走看看