Tempter of the Bone--hdu1010--zoj2110
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 89873 Accepted Submission(s): 24438
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.


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char map[][];
int m,n,bx,by,ex,ey,step,t,flag;
int mov[][]={,,,-,,,-,}; bool can(int x,int y)
{
if(x<||x>m-||y<||y>n-||map[x][y]=='X')
return false;
return true;
}
void DFS(int x,int y)
{ int xx,yy,i;
if(x==ex&&y==ey)//判断是否找到终点
{
if(step==t)
flag=;
return ;
}
if(step>t)
return ;
int dis=t-abs(ex-x)-abs(ey-y)-step;
if(dis<||dis&)//奇偶剪枝
return ;
if(flag==)
return ;//当初我就是没加这一句,在hduoj上超时了,但是在zoj上能过
for(i=;i<;i++)
{
xx=x+mov[i][];
yy=y+mov[i][];
if(can(xx,yy))
{
step++;
map[xx][yy]='X';
DFS(xx,yy);
step--;
map[xx][yy]='.';
}
}
}
int main()
{
int i,j;
while(scanf("%d%d%d",&m,&n,&t),m||n||t)
{
getchar();//吸收回车符
for(i=;i<m;i++)
{
for(j=;j<n;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
bx=i;
by=j;
}
if(map[i][j]=='D')
{
ex=i;
ey=j;
}
}
getchar();
}
flag=;
step=;
int best=abs(ex-bx)+abs(ey-by);
if((best+t)&)//首先判断一下,如果最短路径和要走的步数奇偶性不同,就直接输出NO
{
printf("NO\n");
continue;
}
map[bx][by]='X';
DFS(bx,by);//深搜
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
下面看下修剪前后的时间差距
Tempter of the Bone--hdu1010--zoj2110的更多相关文章
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
传送门:Tempter of the Bone 大意是给一个矩阵,叫你是否可以在给定的可走路径上不重复地走,在最后一秒走到终点. 我用了两个剪枝,且称其为简直001和剪枝002,事实证明001不要都可 ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
- 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 ...
- 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 ...
随机推荐
- jQuery的Autocomplete插件的远程url取json数据的问题
关于远程返回的json数据的展示,以前一样的代码,如果是本地写好的json串数据,插件显示就没有问题,一旦换成ulr方式读取一样的数据,插件就不能正常显示问题了. 今天偶然搜索资料找到一篇csdn上有 ...
- ubuntu 终端只显示当前目录名称
修改.bashrc文件: 原来: #修改终端提示颜色 color_prompt=yes if [ "$color_prompt" = yes ]; then PS1='${debi ...
- cf B. Jeff and Periods
http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...
- 文件锁及其实例,底层文件I/O操作,基本文件操作和实例,Linux中文件及文件描述符概述
http://blog.csdn.net/rl529014/article/details/51336161 http://blog.csdn.net/rl529014/article/details ...
- WCF 基于Cookie的登录验证回传问题的解决
参考资料: http://www.cnblogs.com/czcz1024/p/3333138.html http://megakemp.com/2009/02/06/managing-shared- ...
- WCF的基本知识-仅Http绑定的认知
有关WCF,这3个字母代表的含义,鄙人不会在此细说.喜欢或者不喜欢的,大家勿喷. 入正题,微软从设计.net框架开始,就一直着力于解决程序间的互通信问题.从古老的套接字(Socket)通信到后来的Re ...
- 2015必须推荐的Android框架,猿必读系列!
一.Guava Google 的基于java1.6的类库集合的扩展项目,包括collections, caching, primitives support, concurrency librarie ...
- SRM 599 DIV1
A 首先发现对于2操作,每种素因子可以单独考虑,然后取出步数最多的计入答案,然后分别加上对每种素因子的1操作; 第二步我犯了个错误,以为最优方案是把素因子指数按二进制操作,在1的位置执行1操作,0的位 ...
- Linux远程访问windows时,出现"连接被对端重置"错误
1.sudo apt-get install rdesktop 需要下载 152 kB 的软件包. 解压缩后会消耗掉 512 kB 的额外空间. 2.运行时出现错误 root@oskey- ...
- Activity与Fragment之间的通信
由于Fragment的生命周期完全依赖宿主Activity,所以当我们在使用Fragment时难免出现Activity和Fragment间的传值通信操作. 1.Activity向Fragment,通过 ...