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的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
随机推荐
- java 中的静态(static)代码块
类字面常量 final 静态域不会触发类的初始化操作 非 final static 静态域(以及构造器其实是一种隐式的静态方法) Class.forName():会自动的初始化: 使用 .class来 ...
- USACO 1.4 Arithmetic Progressions
Arithmetic Progressions An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb ...
- 利用JDBC或者事物或者调用存储过程实现往MySQL插入百万级数据
转自:http://www.cnblogs.com/fnz0/p/5713102.html 想往某个表中插入几百万条数据做下测试, 原先的想法,直接写个循环10W次随便插入点数据试试吧,好吧,我真的很 ...
- ios中去除tableView的分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- CentOS 7 NAT模式上网配置
一 VMware 配置 在“编辑”选项卡中,选择“虚拟网络编辑器”,如下图: 选择VMnet8,修改子网IP与子网掩码,注意不要给“使用本地DHCP服务将IP地址分配给虚拟机”选项打勾,如下图: 点击 ...
- 洛谷P4015 运输问题(费用流)
题目描述 WW 公司有 mm 个仓库和 nn 个零售商店.第 ii 个仓库有 a_iai 个单位的货物:第 jj 个零售商店需要 b_jbj 个单位的货物. 货物供需平衡,即\sum\limits ...
- 大数据量.csv文件导入SQLServer数据库
前几天拿到了一个400多M的.csv文件,在电脑上打开要好长时间,打开后里面的数据都是乱码.因此,做了一个先转码再导入数据库的程序.100多万条的数据转码+导入在本地电脑上花了4分钟,感觉效率还可以. ...
- dfs___刷题记录
poj 1564 给出一个s,n个数,输出所有的能够得到s的方案 #include<cstdio> #include<cstring> #include<iostream ...
- 从源码中查看当前android版本
从文件build/core/version_defaults.mk查找PLATFORM_VERSION例如:PLATFORM_VERSION.OPM1 := 8.1.0
- java读取文件流和写入
package jsoup;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStre ...