ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫
直接DFS 直道找到满足条件的路径 或者走全然部可能路径都不满足
注意剪枝 当前位置为(r,c) 终点为(ex,ey) 剩下的时间为lt 当前点到终点的直接距离为 d=(ex-r)+(ey-c) 若多走的时间rt=lt-d<0 或为奇数时 肯定是不可能的 能够自己在纸上画一下 每一个点仅仅能走一次的图 走弯路的话多走的步数一定为偶数
#include<cstdio>
#include<cmath>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = { -1, 1, 0, 0};
const int N = 10;
char mat[N][N];
bool ans;
int t, sx, sy, ex, ey; void dfs(int r, int c, int lt)
{
if(mat[r][c] == 'D' && lt == 0||ans) //满足条件或已经满足条件
{
ans = true;
return;
}
char tc=mat[r][c]; //保存原来的可能值 有'D'和'.'两种情况
mat[r][c] = 'X';
int rt = lt - abs(ex - r) - abs(ey - c); //比直线到达终点多用的时间
if(rt >= 0 && rt % 2 == 0) //剪枝
for(int i = 0; i < 4; ++i) //4个方向走
{
int x = r + dx[i], y = c + dy[i];
if(mat[x][y] == '.' || mat[x][y] == 'D')
dfs(x, y, lt - 1);
}
mat[r][c] = tc; //恢复原状
} int main()
{
int n, m;
while(scanf("%d%d%d", &n, &m, &t), n)
{
for(int i = 1; i <= n; ++i)
scanf("%s", mat[i] + 1);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
{
if(mat[i][j] == 'S') sx = i, sy = j;
if(mat[i][j] == 'D') ex = i, ey = j;
} ans = false;
dfs(sx, sy, t);
printf(ans ? "YES\n" : "NO\n");
}
return 0;
}
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
ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)的更多相关文章
- 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)
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)
点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...
- 题目1461:Tempter of the bone(深度优先遍历DFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1461 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- Tempter of the Bone HDU 1010(DFS+剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- 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 ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
随机推荐
- win32 sdk 列表视图控件绘制
////////////////////////////////////////////////////////////// LRESULT ListViewCustomDraw(HWND hwnd, ...
- Lucene.Net 2.3.1开发介绍 —— 三、索引(五)
原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(五) 话接上篇,继续来说权重对排序的影响.从上面的4个测试,只能说是有个直观的理解了.“哦,是!调整权重是能影响排序了,但是好像没办法来 ...
- 安装logstash,elasticsearch,kibana三件套(转)
logstash,elasticsearch,kibana三件套 elk是指logstash,elasticsearch,kibana三件套,这三件套可以组成日志分析和监控工具 注意: 关于安装文档, ...
- Face-landmarks-detection-benchmark 人脸特征定位网站汇总
源地址:https://www.douban.com/note/525032729/ https://github.com/delphifirst/FaceXhttps://github.com/ ...
- BestCoder Round #3HDU 4907
1. HDU 4907:http://acm.hdu.edu.cn/showproblem.php?pid=4907 中文题我就不说题意了,直接说解题思路吧! ① 第一种思路就是我比赛时的思路,将a数 ...
- sql plus 抢救数据(測)
有索引 --运行plsql脚本 DECLARE TYPE RowIDTab ISTABLE OF ROWID INDEXBY BINARY_INTEGER; CURSORc1 IS selec ...
- 更改EBSserver域名/IP
more: 341322.1 : How to change the hostname of an Applications Tier using AutoConfig 338003.1 : How ...
- Memcached 群集高可用性(HA)架构
Memcache本身并不实现集群功能.假设你想使用Memcahce集群需要使用第三方软件或编程来实现自己的设计,这里将被用来memagent实现代理,memagent也被称为magent.我们注意到, ...
- 解决ScrollView中的ListView无法显示全
问题描述: ListView加入到ScrollView中之后,发现只能显示其中一条,具体原因得看一下源代码.现在先贴一下方案 (转自:http://blog.csdn.net/hitlion2008/ ...
- tomcat各版本和jsp、jstl、servlet的依赖关系(转)
Servlet / JSP / Tomcat Version Servlet/ JSP Tomcat 2.5/2.1 6.0.18 2.4/2.0 5.5.27 2.3/1.2 4.1.3 ...