博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1010 Tempter of the Bone(DFS+剪枝)
阅读量:6621 次
发布时间:2019-06-25

本文共 2623 字,大约阅读时间需要 8 分钟。

Tempter of the Bone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90716    Accepted Submission(s): 24683


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
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 

 |   |   | 

这道题不是求最短时间,而是刚好在那个时间到达。

也要利用好剪枝,否则会超时。

剪枝1:假设起点和终点的最短时间还比t大 一定不能到达。第二个是依据坐标奇偶性,坐标奇偶性就是(x+y)/2。

假设S坐标和D坐标的奇偶性

同样那么就须要偶数步到达。假设不一样就须要奇数步。

#include 
#include
#include
char map[10][10];int dir[4][2]={1,0,-1,0,0,1,0,-1};int vis[10][10],flag,n,m,t;void DFS(int x,int y,int ant){ if(ant==t&&map[x][y]=='D') { flag=1; return ; } if(ant>=t)//假设步数大于t,返回上一步 return ; for(int i=0;i<4;i++) { int x1=x+dir[i][0]; int y1=y+dir[i][1]; if(!vis[x1][y1]&&x1>=0&&x1
=0&&y1
t||(st1+st2+ed1+ed2+t)%2==1)//剪枝1 { printf("NO\n"); continue; } vis[st1][st2]=1; DFS(st1,st2,0); if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}

转载地址:http://kecpo.baihongyu.com/

你可能感兴趣的文章
小程序数据返回时刷新当前页面数据
查看>>
MySQL数据故障时备份与恢复
查看>>
Nlopt优化函数库,用法举例
查看>>
海思 core 电压动态调整
查看>>
jFinal 关联数据库操作
查看>>
比特币为什么需要建立在大量运算之上
查看>>
团队冲刺第二天
查看>>
sed删除空行和开头的空格和tab键
查看>>
php扩展安装
查看>>
Windows与Linux之间的文件自动同步
查看>>
What a C programmer should know about memory
查看>>
MySQL备份账号权限
查看>>
15个重要的Android代码
查看>>
(转)android 牛人必修 ant 编译android工程
查看>>
求最大公约数与最小公倍数
查看>>
C# Winform 跨线程更新UI控件常用方法总结(转)
查看>>
eclipse菜单栏不显示 + the system is running in lou-graphics mode问题
查看>>
【WebService】使用jaxb完成对象和xml的转换
查看>>
如何去除My97 DatePicker控件上右键弹出官网的链接 - 如何debug混淆过的代码
查看>>
CAAnimation动画
查看>>