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
题意:小狗找出口,给你一个n*m的地图和小狗,门的位置,让你小狗能否刚好在t时到达门口;
解题思路:刚开始想的是用广搜求出最小时间,如果最小时间
另外还可以加一个剪枝条件,当然了不加这个也能AC,(n*m-s<=t),t过大的时候肯定不能按时到达了;
感悟:深搜好些但是,剪枝不好写啊,不剪枝就会超时,好烦的!
代码:
#include

#include

#include

#include

#include

#define maxn 205

using namespace std;

int visit[maxn][maxn];//这个是记录步数的不是记录走没走的不能用布尔型

char mapn[maxn][maxn];

int n,m,t,direction[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

int sx,sy,dx,dy;

bool flag;

void dfs(int x,int y,int time)

{

   
if(x<1||x>n||y<1||y>m)//边界

       
return;

   
if(flag==1)

       
return;

   
if(x==dx&&y==dy&&time==t)//找到D了

    {

       
if(time=t)

           
flag=1;

       
return;

    }

    int
temp=(t-time)-abs(x-dx)-abs(y-dy);//奇偶性剪枝

   

   
if(temp<0||temp&1)  return;

   

   

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

    {

       
int x1=x+direction[i][0];

       
int y1=y+direction[i][1];

       
if(mapn[x1][y1]!='X')

       
{

           
mapn[x1][y1]='X';

           
dfs(x1,y1,time+1);

           
mapn[x1][y1]='.';//不满足条件的话就返回

       
}

    }

   
return;

}

int main()

{

    int
s=0;

   
//freopen("in.txt", "r", stdin);

   
while(~scanf("%d%d%d\n",&n,&m,&t)&&n&&m&&t)

{

       
flag=s=0;

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

       
{

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

           
{

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

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

               
{

                   
sx=i;

                   
sy=j;//狗的位置

               
}

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

               
{

                   
dx=i;

                   
dy=j;//门的位置

               
}

               
if(mapn[i][j]=='X')

                   
s++;

           
}

           
scanf("\n");

       
}

       
mapn[sx][sy]='X';

       
memset(visit,0,sizeof(visit));

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

       
//{

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

       
//    {

       
//       
printf("%c",mapn[i][j]);

       
//    }

       
//   
printf("\n");

       
//}

       
if (n*m-s<=t)//提前判断t过大的情况避免再去搜

       
{

           
printf("NO\n");

           
continue;

       
}

       
dfs(sx,sy,0);

       
//printf("最少走 %d 秒 有 %d 秒\n",ans,t);

       
if(flag)

           
printf("YES\n");

       
else

           
printf("NO\n");

    }

}

Tempter of the Bone的更多相关文章

  1. hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  2. ZOJ 2110 Tempter of the Bone

    Tempter of the Bone Time Limit: 2 Seconds      Memory Limit: 65536 KB The doggie found a bone in an ...

  3. hdu 1010:Tempter of the Bone(DFS + 奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

随机推荐

  1. Jquery Ajax type的4种类型

    Ajax type这个里面填什么呢?通常大家都会说get和post.那么还有2个是什么呢 $.ajax({ url: 'http://www.cnblogs.com/youku/', type: '' ...

  2. Dijkstra堆优化学习

    最短路径例题 今天特地学习了Dijkstra的堆优化(主要是慕名已久). 我们需要一个堆来记录[编号,到编号这个点的最短路径值(当然只是当前的)] 与原来的Dijkstra操作基本一致,主要有以下几点 ...

  3. 每周分享之 二 http协议(2)

    本次分享http协议,共分为三部分,这是第二部分,主要讲解请求与响应的字段,以及状态码. 以http/1.1版本的一个完整的请求与响应作为例子 http请求信息由三部分组成 1.请求方法(GET/PO ...

  4. leetCode没那么难啦 in Java (二)

    介绍    本篇介绍的是标记元素的使用,很多需要找到正确元素都可以将正确元素应该插入的位置单独放置一个标记来记录,这样可以达到原地排序的效果. Start 27.RemoveElement 删除指定元 ...

  5. hdu1356&hdu1944 博弈论的SG值(王道)

    S-NimProblem DescriptionArthur and his sister Caroll have been playing a game called Nim for some ti ...

  6. (Java后端 Java web)面试时如何展示自己非技术方面的能力(其实就是综合能力)

    这篇文章的适用范围其实不仅限于Java后端或Java Web,不过其中有些是拿这方面举例的,在其它方面,大家可以举一反三,应该也能得到些启示. 我们在面试时,会发现有些候选人技术不错,比如在Java ...

  7. 大数据开发 | MapReduce介绍

    1.  MapReduce 介绍 1.1MapReduce的作用 假设有一个计算文件中单词个数的需求,文件比较多也比较大,在单击运行的时候机器的内存受限,磁盘受限,运算能力受限,而一旦将单机版程序扩展 ...

  8. ubuntu中使用usb-creator制作live usb

    1.实验环境 ubuntu14.04 2.启动usb-creator 2.1 单击桌面左上角的搜索图标,输入usb-creator,然后选择“应用程序"中的”启动盘创建器“ 2.2 终端中输 ...

  9. python contextlib 上下文管理器

    1.with操作符 在python中读写文件,可能需要这样的代码 try-finally读写文件 file_text = None try: file_text = open('./text', 'r ...

  10. C++类中静态变量和静态方法使用介绍

    静态成员的提出是为了解决数据共享的问题.实现共享有许多方法,如:设置全局性的变量或对象是一种方法.但是,全局变量或对象是有局限性的.这一章里,我们主要讲述类的静态成员来实现数据的共享. 静态数据成员 ...