# FZU 1046 Tempter of the Bone

3447人阅读 评论(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时间，退出递归搜索。

0
0

个人资料
• 访问：3556539次
• 积分：36089
• 等级：
• 排名：第136名
• 原创：402篇
• 转载：88篇
• 译文：5篇
• 评论：3425条
个人说明
联系方式：
文章存档
最新评论