https://vjudge.net/contest/67836#problem/C

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

时间复杂度:

题解:dfs

代码:

#include <bits/stdc++.h>
using namespace std; int N, M, T;
int sx, sy, ex, ey;
char maze[10][10];
int flag = 0;
int flagg[10][10];
int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1}; void dfs(int nx, int ny, int step) {
if(nx == ex && ny == ey) {
if(step == T)
flag = 1;
return ;
}
for(int i = 0; i < 4; i ++) {
int xx = nx + dx[i], yy = ny + dy[i];
if(xx > 0 && xx <= N && yy > 0 && yy <= M && maze[xx][yy] != 'X' && flagg[xx][yy] == 0) {
flagg[xx][yy] = 1;
dfs(xx, yy, step + 1);
flagg[xx][yy] = 0;
}
}
} int main() {
while(~scanf("%d%d%d", &N, &M, &T)) {
if(!N && !M && !T) break;
flag = 0;
memset(flagg, 0, sizeof(flagg));
for(int i = 1; i <= N; i ++) {
scanf("%s", maze[i] + 1);
for(int j = 1; j <= M; j ++) {
if(maze[i][j] == 'S') {
sx = i;
sy = j;
}
if(maze[i][j] == 'D') {
ex = i;
ey = j;
}
}
}
flagg[sx][sy] = 1;
dfs(sx, sy, 0);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

ZOJ 2110 C - Tempter of the Bone的更多相关文章

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

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

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

  3. zoj 2110 Tempter of the Bone (dfs)

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

  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+奇偶剪枝)

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

  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. HDU 1010 Tempter of the Bone --- DFS

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

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

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

随机推荐

  1. master.HMaster: Failed to become active master

    Hbase集群启动后自动退出,日志错误: fatal error: master.HMaster: Failed to become active master java.io.IOException ...

  2. python网络编程之线程

    一 .背景知识 1.进程 之前我们已经了解了操作系统中进程的概念,程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别就在于:程序是指令 ...

  3. java web 开发模式

    1.Model1 javaBean+jsp:jsp直接操作数据库,不安全,开发维护复杂 2.Model2:MVC 原理:把Model1的操作javaBean操作抽取为控制层 实现:控制层使用servl ...

  4. 成都Uber优步司机奖励政策(1月17日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. miniz库简介及使用

    miniz:Google开源库,它是单一的C源文件,紧缩/膨胀压缩库,使用zlib兼容API,ZIP归档读写,PNG写方式.关于miniz的更详细介绍可以参考:https://code.google. ...

  6. hive整合sentry,impala,hue之后权限管理操作

    7.Hive授权参考(开启sentry之后,对用户授权用不了,只能针对用户组,grant role testrole to user xxxxxxx; ) 7.1:角色创建和删除 create rol ...

  7. DE1-SOC工程helloworld-第一篇(未完成)

    1. 参考官方的文档,第一个问题就是电脑上需要安装ubuntu虚拟机吗? 2. 创建一个“Hello world”工程:在Linux terminal 上打印信息. 3. 说是让安装个EDS软件,先去 ...

  8. 「日常训练」Known Notation(ZOJ-3829)

    题意与分析 题意是这样的:给一个字符串,字符串中只包含数字和运算符'*'.现在问字符串是不是一个合法的逆波兰式(后缀表达式).已知逆波兰式的空格消除,也就是说123可以看成123也可以看成1和23.如 ...

  9. 关于Python 中的 if 语句

    学习Python,最开始我们都是先从函数学起,Python教程中有很多函数,if算是其中之一. 可能最为人所熟知的编程语句就是 if 语句了.例如: >>> >>> ...

  10. 小程序页面的四种文件(JSON、WXML、WXSS、JS)加载顺序

    一个小程序页面由四种文件组成: 1)json 页面配置文件 2)js 页面逻辑文件(必需) 3)wxml 页面结构文件(必需) 4)wxss 页面样式文件 这四个文件的加载顺序: 第一步: 加载页面j ...