ZOJ 2110 C - Tempter of the Bone
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的更多相关文章
- 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 ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- 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 ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- 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 ...
- 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 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 ...
- 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 ...
随机推荐
- python学习之文件读写入门(文件读的几种方式比较)
1.文件读写简单实例:(以w写的方式打开一个文件,以r读一个文件) # Author : xiajinqi # 文件读写的几种方式 # 文件读写 f = open("D://test.txt ...
- 第5天 Java基础语法
第5天 Java基础语法 今日内容介绍 方法 方法 方法概述 在我们的日常生活中,方法可以理解为要做某件事情,而采取的解决办法. 如:小明同学在路边准备坐车来学校学习.这就面临着一件事情(坐车到学校这 ...
- ChipScope Pro Inserter - "ERROR:NgdBuild:924 - bidirect pad net '<oDRAM0_A>' is driving non-buffer primitives
解决方案: Using a IOBUF signal as a trigger for the ILA Inserter flow will cause a NGDBuild error. These ...
- javascript array.property.slice.call
function foo() { //var var1=Array.prototype.slice.call(arguments); var var1=[].slice.call(arguments) ...
- uCOS-II中的任务切换-图解多种任务调度时机与问题
[@.1 任务调度时机] 之前的一篇文章分析了具体的uCOS-II中的任务切换机制,是从函数调用的角度上分析的.这次我具体从整个程序运行的时间上来看,分析多种任务调度发生的时机.以下所有图片均可点击放 ...
- 4245: [ONTAK2015]OR-XOR
4245: [ONTAK2015]OR-XOR https://www.lydsy.com/JudgeOnline/problem.php?id=4245 /* 要求分成m份,总价值为a1|a2|a3 ...
- P1294 高手去散步
P1294 高手去散步 题目背景 高手最近谈恋爱了.不过是单相思.“即使是单相思,也是完整的爱情”,高手从未放弃对它的追求.今天,这个阳光明媚的早晨,太阳从西边缓缓升起.于是它找到高手,希望在晨读开始 ...
- CLR via C#读书笔记二:类型基础
1.CLR允许将对象转换为它的(实际)类型或者它的任何基类型. 2.is操作符检测对象是否兼容于指定类型,is操作符永远不抛出异常. 3.as操作符返回对同一个对象的非null引用.如果对象不兼容,a ...
- MyBatis-mybatis全局映射文件解析
全局配置文件为mybatis-config.xml 1.properties标签 <properties resource="dbconfig.properties"> ...
- 流式断言器AssertJ介绍
本文来自网易云社区 作者:范旭斐 大家在使用testng.junit做自动化测试的过程中,经常会用到testng.junit自带的断言器,有时候对一个字符串.日期.列表进行断言很麻烦,需要借助到jdk ...