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. 苹果笔记本调整 pycharm 字体大小的地方

    我想,对于习惯了使用windows版本 或者 乌班图版本 的pycharm 的人而言, mac版本调节字体的地方藏的实在是太坑爹了.

  2. php性能优化三(PHP语言本身)

    0.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册 ...

  3. [Objective-C语言教程]动态绑定(32)

    动态绑定确定在运行时而不是在编译时调用的方法. 动态绑定也称为后期绑定. 在Objective-C中,所有方法都在运行时动态解析.执行的确切代码由方法名称(选择器)和接收对象确定. 动态绑定可实现多态 ...

  4. Linux 服务器加入Windows AD

    背景信息: Windows AD Version: Windows Server 2012 R2 zh-cn 计算机全名:hlm12r2n1.hlm.com 域:hlm.com 域控管理员:stone ...

  5. Oracle ltrim() rtrim() 函数详细用法

    今天在论坛里看了一篇帖子,讨论ltrim() 函数的详细用法,下面我借几个高手的回答总结一下: 先看几个实例: SQL> select ltrim('109224323','109') from ...

  6. 设计简单登录界面(Java web)

    程序设计思想: 在Input.jsp中创建一个表格里边分别是课程名称,任课老师,教学地点,并分别用三个文本框来接受输入的三个属性, 并传到另外的Jsp页面中,又来接受三个数据,并判断传来的教师,与教室 ...

  7. Eclipse 的SVN 插件

    Eclipse 的SVN 插件 简介  Subversive Eclipse 团队开发的SVN 插件. Subclipse Apache 的SVN 团队开发的Eclipse 插件.   Subvers ...

  8. FPGA实战操作(2) -- PCIe总线(协议简述)

    目录 1. PCIe基础知识 2. 事务层协议 2.1 数据包结构 2.2 帧头含义详述 3. 报文举例 3.1 寄存器读报文 3.2 完成报文 4. 机制简述 4.1 Non-Posted和Post ...

  9. ator自动生成mybatis配置和类信息

    generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包.        网址:http://cod ...

  10. OpenERP 干掉 产品计量单位中的 search more 和 create and edit

    实际操作中特别容易点错而新建了重复的单位,通过下边的方法可以将“search more”和 “create and edit”干掉 在新继承product.product的模块中,修改xml文件 这样 ...