FZU 1046 Tempter of the Bone

标签: input character each layout less 制造
3580人阅读 评论(1) 收藏 举报
分类:

 

Tempter of the Bone


Time Limit :1s Memory limit :32M
Accepted Submit :305 Total Submit :1026

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

 

解题:

       搜索题,一直是我棘手的问题。本题涉及到深度搜索(当然也可以广度搜索)+剪枝,典型的迷宫问题。问题的大概意思是,狗在S点,门在D点,门只有在T时刻才开,迷宫为N*M矩阵,迷宫内有X代表的墙。问是否狗能准时逃出来。我们要制造一个计划,让狗能在T时刻刚好到达门口,一般思路可以来回走动,快到T时候再到门口。但是题目要求狗每次走的地方都将会陷下去,不能回走,只能绕路走,能绕路走可定要多出偶数的步数,就算是墙挡着也一样如此,可以看草图:

两种不同的走法,下面那一种可以控制时间刚好在T时刻。因为差出的是偶数,所以奇数的话要剪枝掉,省掉搜索时间。而另一个剪枝,路径剪枝,是在开始的时候,将如迷宫的每个地方都走过了,而还没到门开的时间,这时也逃生不了,因为没地方回走了,都塌陷了。

        深度搜索下去,直到所用的步数刚好等于给定的T时间,退出递归搜索。

查看评论

HDU1010 Tempter of the Bone(小狗是否能逃生----DFS)

Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...
  • Hush_lei
  • Hush_lei
  • 2014-08-14 13:02:22
  • 1531

Tempter of the Bone(DFS+奇偶剪枝)

Tempter of the Bone Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u S...
  • cs_zlg
  • cs_zlg
  • 2013-01-26 22:04:13
  • 2026

Tempter of the Bone解析(回溯算法)hdu1010 zoj2110

Tempter of the BoneProblem DescriptionThe doggie found a bone in an ancient maze, which fascinated h...
  • qq943574281
  • qq943574281
  • 2011-03-19 14:38:00
  • 873

HDU 1010 Tempter of the Bone

HDU 1010 Tempter of the Bone 题目大意: 给定N*M一张图,问你从起点S到终点D不经过障碍物X恰好K步能否到达? 解题思路: 利用回溯法搜索1条路径即可。 但是注意剪...
  • a1061747415
  • a1061747415
  • 2014-05-21 10:58:07
  • 762

杭电ACM 1010 搜索题

Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However...
  • cyg0810
  • cyg0810
  • 2012-11-17 16:51:29
  • 5660

杭电ACM1010

Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However,...
  • haifeng319
  • haifeng319
  • 2015-11-13 21:36:34
  • 168

ZOJ - 2110 Tempter of the Bone

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe...
  • Puyar_
  • Puyar_
  • 2016-01-30 22:06:15
  • 201

FZU 2254 英语考试 (最小生成树)(福州大学第十四届程序设计竞赛)

英语考试Problem Description 在过三个礼拜,YellowStar有一场专业英语考试,因此它必须着手开始复习。这天,YellowStar准备了n个需要背的单词,每个单词的长度均为m。...
  • blessLZH0108
  • blessLZH0108
  • 2017-07-15 08:35:09
  • 959

HDU 1010 Tempter of the Bone(深搜+剪枝)

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe...
  • nka_kun
  • nka_kun
  • 2017-07-29 17:04:54
  • 183

HDOJ 1O10 Tempter of the Bone

这道题是一道相当经典的DFS+剪枝。。。做这道题收获比较大,能让你学会几个剪枝技巧。。 一般做这道题的都会把DFS写出来,不难,关键是超时怎么处理,反正在我看了网上的关于剪枝技巧后,当时就有一个感觉...
  • anjiashuai521
  • anjiashuai521
  • 2012-07-03 13:10:16
  • 682
    个人资料
    等级:
    访问量: 361万+
    积分: 3万+
    排名: 139
    文章存档
    最新评论