hdoj 1010-Tempter of the Bone
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.
'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.
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
YES
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace::std; int N,M,T,t;
char maps[][];
int maps_[][];
int stx,sty,enx,eny;
int a[][] = {{,},{-,},{,},{,-}};
bool dfs(int n,int m)
{
if( n == enx && m == eny && t == T )
{
return true;
} int ans = T-t-abs(enx-n)-abs(eny-m); //奇偶剪枝,感觉好吊。
if(ans< || ans&)
return false; for(int i = ;i<;i++)
{
int x = n + a[i][];
int y = m + a[i][];
if(maps[x][y] != 'X' && maps_[x][y] != && x>= && y>= && x<N && y<M)
{
t++;
maps_[x][y] = ; if(dfs(x,y))
return true;
else{
t--;
maps_[x][y] = ;
} }
}
return false;
}
int main()
{
while(scanf("%d %d %d",&N,&M,&T) && N != )
{
memset(maps,,sizeof(maps)); //每次输入把地图和标记清空
memset(maps_,,sizeof(maps_));
for(int i=; i<N; i++)
{
scanf("%s",&maps[i]);
for(int j = ; j<M;j++)
{
if(maps[i][j] == 'S') //起始点
{
stx = i;
sty = j;
}
else if(maps[i][j] == 'D') //终点
{
enx = i;
eny = j;
}
}
}
t = ;
maps_[stx][sty] = ; //标记起点
if(dfs(stx,sty))
{
printf("YES\n");
}else
printf("NO\n");
}
return ;
}
hdoj 1010-Tempter of the Bone的更多相关文章
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- 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 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
- 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 分类: 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 ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
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 ...
随机推荐
- js 移动端之监听软键盘弹出收起
js 移动端关于页面布局,如果底部有position:fixed的盒子,又有input,当软键盘弹出收起都会影响页面布局.这时候Android可以监听resize事件,代码如下,而ios没有相关事件. ...
- jq + 面向对象实现拼图游戏
jq + 面向对象实现拼图游戏 知识点 拖拽事件 es6面向对象 jquery事件 效果图 html: <div class="wraper"> <div cla ...
- <P>标签是什么?怎么用!
<P>标签它是一个段落标签,它和<br>标签不一样.会自行起一行段落,并且可以作为一个盒子来使用.可以单独定义它. 比如下图: <p>这个就是一个段落</p& ...
- python 版本号比较 重载运算符
# -*- coding: utf-8 -*- class VersionNum(object): """ 版本号比较 默认版本以“.”分割,各位版本位数不超过3 例一: ...
- MySQL学习之基础篇09-事务
我们在建表的时候通常会在最后声明引擎类型,这次我们就来看看存储引擎都有哪些: 举个例子: --------------------------- 银行转账: 张三想给李四转500元钱: 张三-500 ...
- wget下载出现错误 403:Forbidden
在我尝试wget下载一张图片的时候,出现了如下错误: wget "https://k4b8k3x5.ssl.hwcdn.net/content/140516/1622-saaya-irie- ...
- k8s 如何支持私有镜像
k8s如何支持私有镜像 实现无密钥编排 kubectl create secret docker-registry regsecret --docker-server=registry.cn-shen ...
- Spring源码窥探之:Spring AOP初步使用
AOP即面向切面编程.它的底层实际是用了spring的动态代理,具体是JDK的代理还是CGLIB的代理,就视情况而定了.本博客园仅仅作为平时记录,显得有些杂乱无章,如果想了解动态代理,设计模式,请访问 ...
- 火狐谷歌webdriver驱动地址
ChormeDrive下载 打开百度搜索Chromedriver官网下载,点击进入这个页面,链接为:http://npm.taobao.org/mirrors/chromedriver/2.41/ ...
- C 语言程序设计
C 语言数据类型: 整数: char(也是字符型) short int long 浮点型: float double 指针 自定义类型 输入输出格式化: int ->%d long ->% ...