Tempter of the Bone


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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: Zhejiang Provincial Programming Contest 2004

 //C++    20    172    姜伯约
/* 题意:
从S走向D,问能否恰好在第t个时刻走到 DFS:
比较经典的一道深搜,奇偶剪枝是比较亮的一点,亲可以自己手动画图
比较一下,会获益不少,其他和普通的dfs差不多。 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,m,t;
char g[][];
int mov[][]={,,,,,-,-,};
int flag,ex,ey;
void dfs(int x,int y,int cnt)
{
if(cnt>t || flag) return;
if(x==ex && y==ey && cnt==t) flag=;
int temp=(t-cnt)-abs(x-ex)-abs(y-ey);
if(temp< || (temp&))return; //奇偶剪枝
for(int i=;i<;i++){
int tx=x+mov[i][];
int ty=y+mov[i][];
if(tx>= && tx<n && ty>= && ty<m && g[tx][ty]!='X'){
g[tx][ty]='X';
dfs(tx,ty,cnt+);
g[tx][ty]='.';
}
}
}
int main(void)
{
while(scanf("%d%d%d",&n,&m,&t)!=EOF&&(n+m+t))
{
int x,y;
int cnt=;
for(int i=;i<n;i++){
scanf("%s",g[i]);
for(int j=;j<m;j++){
if(g[i][j]=='S')
x=i,y=j;
else if(g[i][j]=='.') cnt++;
else if(g[i][j]=='D') ex=i,ey=j;
}
}
if(cnt+<t){
puts("NO");continue;
}
flag=;
g[x][y]='X';
dfs(x,y,);
if(flag) puts("YES");
else puts("NO");
}
return ;
}

zoj 2110 Tempter of the Bone (dfs)的更多相关文章

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

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

  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. ZOJ 2110 Tempter of the Bone(DFS)

    点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...

  4. HDU1010:Tempter of the Bone(dfs+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010   //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...

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

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

  6. 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 ...

  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. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...

  9. M - Tempter of the Bone(DFS,奇偶剪枝)

    M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

随机推荐

  1. RDVTabBarController--可自由定制的iOS底部导航控件

    RDVTabBarController:一个十分完善的tabBarController,可以自定义角标个数,爽的停不下来. RDVTabBarController地址:RDVTabBarControl ...

  2. spring-bean(xml方式管理)

    特点 每一次加载XML文件时候,都会将配置文件中包含的配置实例化. ID与name区别:name不是唯一的,但是可以使用特殊字符 Class:生成类的实例 Bean的作用域: 三种实例化方式 类的构造 ...

  3. Thymeleaf显示Map集合数据

    <select class="form-control zz-set-input-size" id="channel"> <option va ...

  4. 路由器基础配置之rip

    我们将以上面的拓扑图进行实验,用rip协议来进行实验,目的是实现三台不同网段的pc机之间实现互相通信 首先为pc机配置好ip地址和网关,配置完IP地址后在配置路由器 router1: enable 进 ...

  5. 分享spring、spring boot、spring cloud一些学习资源,从基础知识到项目实战

    1.spring注解驱动开发,学习spring boot和spring cloud必备知识 链接: https://pan.baidu.com/s/1xhULzLlpkERhoMi1G5Lgfg 密码 ...

  6. JAVAOOP异常

    排序: Try-catch-finally:try正常执行,如果有异常执行catch后执行finally,如果没有直接执行finally 执行顺序:try-catch:try中的语句正常执行,如果遇到 ...

  7. pytorch中如何使用预训练词向量

    不涉及具体代码,只是记录一下自己的疑惑. 我们知道对于在pytorch中,我们通过构建一个词向量矩阵对象.这个时候对象矩阵是随机初始化的,然后我们的输入是单词的数值表达,也就是一些索引.那么我们会根据 ...

  8. Makefile (2) gdb

    gdb调试 1.用debug的方式编译 -g 2.打上断点 3.单步调试 step into 进入函数里面 step over 运行整个函数 step return 跳出当前函数 4.继续运行 5.打 ...

  9. PAT Basic 1057

    1057 数零壹 给定一串长度不超过 10​5​​ 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有 ...

  10. Servlet过滤器---编码转换过滤器

    该实例用于将请求与相应的编码设置为当前网站的默认编码 java类: import java.io.IOException; import javax.servlet.Filter; import ja ...