hdoj--1010--Tempter of the Bone(搜索+奇偶剪枝)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 93821 Accepted Submission(s): 25482
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.
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.
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
NO
YES
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char map[10][10];
int vis[10][10];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int m,n,t,flog;
int sx,sy,ex,ey;
void dfs(int x,int y,int l)
{
if(flog)
return ;
if(map[x][y]=='D'&&l==t)
{
flog=1;
return ;
}
int temp=t-abs(ex-x)-abs(ey-y)-l;//当前的位置到达终点的最短距离
if(temp<0||temp&1)
return ;
for(int i=0;i<4;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=0&&ny>=0&&nx<n&&ny<m&&!vis[nx][ny]&&map[nx][ny]!='X'&&l+1<=t)
{
vis[nx][ny]=1;
dfs(nx,ny,l+1);
vis[nx][ny]=0;
}
}
}
int main()
{
while(scanf("%d%d%d",&n,&m,&t),m||n||t)
{
int w=0;
memset(map,'\0',sizeof(map));
for(int i=0;i<n;i++)
{
scanf("%s",map[i]);
for(int j=0;j<m;j++)
{
if(map[i][j]=='S')
sx=i,sy=j;
if(map[i][j]=='D')
ex=i,ey=j;
if(map[i][j]=='X')
w++;
}
}
memset(vis,0,sizeof(vis));
vis[sx][sy]=1;
flog=0;
// if(t<n*m-w)
dfs(sx,sy,0);
if(flog)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
hdoj--1010--Tempter of the Bone(搜索+奇偶剪枝)的更多相关文章
- 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+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- 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 ...
- 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 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu Tempter of the Bone (奇偶剪枝)
学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.h ...
- Tempter of the Bone 搜索---奇偶性剪枝
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
随机推荐
- 2016.02.23,英语,《Vocabulary Builder》Unit 01
Bell:来源于拉丁语,含义为war.fight,其中Bellona [bә'lәunә]是罗马女战神的名字,她的丈夫是战神Mars.antebellum: [ˌænti'beləm] adj. 战前 ...
- UESTC--1271--Search gold(贪心)
Search gold Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Submit Sta ...
- 【BZOJ 2821】作诗
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2821 [算法] 如果不强制在线,显然莫队是可以解决此题的,那么,强制在线怎么办呢? ...
- 杂项-DB:数据库
ylbtech-杂项-DB:数据库 数据库,简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新增.截取.更新.删除等操作. 所谓“数据库”是以一定方式储存在一起.能与 ...
- query.setFirstResult解析
转自:https://blog.csdn.net/thinkingcao/article/details/78053622
- springMVC、mybatis实现的登录页面(maven)
首先项目结构 pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...
- java实现sql批量插入参数
背景: 需要更新一些不规范的时间格式,如将某个时间格式化为yy-MM-dd,实际上为 yy-MM-dd hh:mm:ss,并且需要提供回滚脚本. 例如:规范化时间的脚本如下: ,) WHERE tes ...
- PHP日期和时间处理组件-Carbon
https://packagist.org/packages/nesbot/carbon 我们使用PHP时经常需要处理日期和时间,有时会被时间时区搞混淆,而Carbon是PHP中很人性化的时间日期处理 ...
- Java基础——选择排序、冒泡排序
1.选择排序 原理是直接从待排序数组里选择一个最小(或最大)的数字,每次都拿一个最小数字出来, 顺序放入新数组,直到全部拿完 代码演示: public class Test3 { public sta ...
- 基于XMPP利用openfire简单的即时通讯
功能的实现结果:能够使自己编写客户端与spark客户端信息通讯,将接受到的信息更新到textview上. 1.下载openfire并安装.设置域名,添加用户 2.下载安装spark客户端 3.jar包 ...