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. django-models 数据库取值

    django.shortcuts import render,HttpResponse from app01.models import * # Create your views here. def ...

  2. Flask后台管理

    管理后台主页 需求 为后台主页提供专门的视图函数 需要带入当前管理员用户相关信息以便在界面进行展示 代码实现 在 modules/admin/views.py 文件中添加视图函数 @admin_blu ...

  3. 高斯消元c++(非常暴力)

    暴力方法(已更新): #include<iostream> using namespace std; const int maxn = 1000; int n; double a[maxn ...

  4. R tutorial

    http://www.clemson.edu/economics/faculty/wilson/R-tutorial/Introduction.html https://www.youtube.com ...

  5. Caliburn.Micro 杰的入门教程5,Window Manager 窗口管理器

    Caliburn.Micro 杰的入门教程1(翻译)Caliburn.Micro 杰的入门教程2 ,了解Data Binding 和 Events(翻译)Caliburn.Micro 杰的入门教程3, ...

  6. 无偏方差为什么除以n-1

    设样本均值为,样本方差为,总体均值为,总体方差为,那么样本方差有如下公式:. 很多人可能都会有疑问,为什么要除以n-1,而不是n,但是翻阅资料,发现很多都是交代到,如果除以n,对样本方差的估计不是无偏 ...

  7. VDI数据恢复

    环境:cirtix xendesktop 问题:VDI无法正常启动,后台登录查看报错.多次重启无效果,客户部分数据存放在启动盘. 解决方法:1.创建一台新的VDI(必须保证关机)2.将原有VDI启动盘 ...

  8. hugepages_settings.sh

    #!/bin/bash## hugepages_settings.sh## Linux bash script to compute values for the# recommended HugeP ...

  9. JS里点击事件判断是否 触发了节点 和给标签添加class属性

    $("#activityType").click(function(e){ if(e.target==$("#bb")[0]){ var bb=document ...

  10. 【json提取器】- 提取数据的方法

    json 提取器的使用 方法 json 提取器  提取的结果   我用调试取样器进行查看