Tempter of the Bone

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 1
Problem Description
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
 
Author
ZHANG, Zheng
 
Source
ZJCPC2004
 
在T时刻,到达。
 
 
 
详细的看代码。开始做的时候,一直超时。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; int n,m,T,sx,sy,dx,dy;
char a[][];
bool vis[][],Glag;
int map1[][]={ {,},{,},{-,},{,-} }; void dfs(int x,int y,int cur)
{
int i,x1,y1;
if(cur==T && x==dx && y==dy)
{
Glag=true;
return;
}
if(Glag==true) return;
int t,s;
t=T-cur;
s=(int)abs(dx-x)+(int)abs(dy-y);//剩余的时间 t - 剩余的步数 s
//如果,t是奇数,s是奇数。那么t-s是偶数。
//如果,t是偶数,s是奇数。那么t-s是奇数。
//所以只要判断 相减后是否>0 && 偶数。
t=t-s;
if(t<||(t&)==) return;//奇偶性剪枝 for(i=;i<;i++)
{
x1=x+map1[i][];
y1=y+map1[i][];
if(x1>=&&x1<=n && y1>=&&y1<=m && vis[x1][y1]==false && a[x1][y1]!='X')
{
vis[x1][y1]=true;
dfs(x1,y1,cur+);
vis[x1][y1]=false;
}
}
} int main()
{
int i,j,wall;
while(scanf("%d%d%d",&n,&m,&T)>)
{
if(n==&&m==&&T==)break;
for(i=;i<=n;i++)
scanf("%s",a[i]+); wall=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(a[i][j]=='S')
{
sx=i;
sy=j;
}
else if(a[i][j]=='D')
{
dx=i;
dy=j;
}
else if(a[i][j]=='X')
wall++; if(n*m--wall<T)//这也是一个优化,T太大了,根本走不到。
{
printf("NO\n");
continue;
}
Glag=false;
memset(vis,false,sizeof(vis));
vis[sx][sy]=true;
dfs(sx,sy,);
if(Glag==true)
printf("YES\n");
else printf("NO\n");
}
return ;
}
 
 

Tempter of the Bone 搜索---奇偶性剪枝的更多相关文章

  1. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

  2. 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 ...

  3. hdu 1010 Tempter of the Bone (奇偶性剪枝)

    题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...

  4. 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 ...

  5. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. 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 ...

  7. M - Tempter of the Bone(DFS,奇偶剪枝)

    M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  8. 【HDU - 1010】Tempter of the Bone(dfs+剪枝)

    Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...

  9. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. python 将列表嵌套字典的unicode字符串转换为str格式的字符串的方法

    今天在进行django开发的过程中遇到了一个非常棘手的问题, 因为需求原因, 需要将一份数据存为json格式到数据库中, 如下面这种格式: list_1 = [{"name":&q ...

  2. aspx代码审计-1

    今天和大家分享一下aspx网站的代码审计,漏洞类型就是SQL注入和cookie欺骗. 本文作者:i春秋签约作家——非主流 今天看的cms名字叫做:XX星员工请假系统 我们首先看一下网站的目录结构: 其 ...

  3. 一篇文章搞懂Linux安全!

    Linux是开放源代码的免费正版软件,同时也是因为较之微软的Windows NT网络操作系统而言,Linux系统具有更好的稳定性.效率性和安全性. 在Internet/Intranet的大量应用中,网 ...

  4. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)

    今天运行Redis时发生错误,错误信息如下: org.springframework.dao.InvalidDataAccessApiUsageException: MISCONF Redis is ...

  5. RN 47 中的 JS 线程及 RunLoop

    RCBridge 初始化时声明了一个 CADisplayLink _jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector ...

  6. Java方法区

    方法区 在一个jvm实例的内部,类型信息被存储在一个称为方法区的内存逻辑区中.类型信息是由类加载器在类加载时从类文件中提取出来的.类(静态)变量也存储在方法区中. jvm实现的设计者决定了类型信息的内 ...

  7. c#StreamWriter,StreamReader类(主要用于文本文件访问)

    1.为什么要使用StreamReader或者StreamWriter 如果对文本文件需要读取一部分显示一部分则使用FileStream会有问题,因为可能FileStream会在读取的时候把一个汉字的字 ...

  8. Mac下的浏览器类似Windows中Ctrl+F5的不请求缓存刷新页面的快捷键

    正常方式: [shitf]+[command]+[r] 如果改过快捷键的: [fn]+[shift]+[command]+[f]

  9. Android多媒体之view,SurfaceView,GLSurfaceView

    1.相关概念 不用画布,直接在窗口上进行绘图叫做无缓冲绘图. 用了一个画布,将所有内容都先画到画布上,在整体绘制到窗口上,就该叫做单缓冲绘图, 那个画布就是一个缓冲区.用了两个画布,一个进行临时的绘图 ...

  10. Tomcat *的下载(绿色版和安装版都适用)

    不多说,直接干货! 1.先下载tomcat,到http://tomcat.apache.org/ 2.注意:下载可以下载zip格式或exe格式的,其中zip格式的只要解压缩再配置下环境变量就可以使用了 ...