HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 15 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
'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
Sample Input
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
NO
YES
Author
Source
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int dr[][]={{,},{,},{-,},{,-}};
int f[][];
char mp[][];
int sx,sy,tx,ty,t,n,m,i,j;
int check(int x,int y)
{
if (x>= && x<n && y>= && y<m && mp[x][y]!='X' && !f[x][y]) return ;
else return ;
}
int dfs(int x,int y,int time)
{
if (time== && x==tx && y==ty)
return ;
for(int i=;i<;i++)
{
int xx=x+dr[i][];
int yy=y+dr[i][];
if (check(xx,yy))
{
f[xx][yy]=;
if (dfs(xx,yy,time-)) return ;
f[xx][yy]=;
}
}
return ;
} int main()
{
while(scanf("%d%d%d",&n,&m,&t) && n!=)
{
for(i=;i<n;i++)
{
scanf("%s",&mp[i]);
for(j=;j<m;j++)
if (mp[i][j]=='S') sx=i,sy=j;
else if (mp[i][j]=='D') tx=i,ty=j;
}
if (t==)
{
if (sx!=tx && sy!=ty) printf("NO\n");
else if (sx==tx && sy==ty) printf("YES\n");
continue;
}
if (abs(tx-sx)+abs(ty-sy)>t || (t-abs(tx-sx)-abs(ty-sy))%!=) {printf("NO\n");continue;} memset(f,,sizeof(f));
f[sx][sy]=;
if (dfs(sx,sy,t)) printf("YES\n");
else printf("NO\n");
} return ;
}
HDU 1010 Temper of the bone(深搜+剪枝)的更多相关文章
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1010 Tempter of the Bone(深度+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- 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 ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU 1010 Tempter of the Bone (DFS+剪枝)
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...
- Hdu1010Tempter of the Bone 深搜+剪枝
题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’:判断能否从S正好走t步到D. 题解:dfs,奇偶性减枝,剩余步数剪枝. ps:帮室友Debug的题:打错了两个字 ...
- hdu 1010 Tempter of the Bone (奇偶性剪枝)
题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
随机推荐
- c++的输入和输出流
C++编译系统提供了用于输入输出的iostream类库.iostream这个单词是由3个部 分组成的,即i-o-stream,意为输入输出流.在iostream类库中包含许多用于输入输出的 类.常用的 ...
- php 排序
for($i=1;$i<count($result);$i++) { $tmp = $result[$i]['PNL']; $tmp_ = $result[$i]; $j=$i-1 ; for( ...
- SDK does not contain any platforms. error (android)
By default sdk was installed under the C:\Users\<user_name>\AppData\Local\Android\sdk\ directo ...
- javascript动画效果之透明度
在css中的filter对应老版本的ie浏览器,opacity对应的是其他浏览器 <!DOCTYPE html> <html> <head> <meta ch ...
- 设计模式4 外观模式 FACADE
一个外观是一个类,其提供的功能介于工具箱的功能和完整系统的功能之间,并为一个包或者一个子系统中的类提供了简化的使用方式.
- 为什么yslow用不了
因为yslow暂时不支持 Firefox 36以上版本.建议您可以使用它的书签版.访问这里 http://yslow.org/mobile/把页面最后的那个 Desktop Bookmarklet I ...
- Openlayer 3 的画线测量长度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- hadoop 及hbase zookeeper 经常出现问题
往往是以下几个 1/ 各节点时间不统一(写shell文件统一时间) 2/配置文件 /etc/hosts文件中ip地址配置错误(更新ip) 3/断网后重启机器 ip地址被修改(更新配置文件中的ip)
- 【01-14】java ThreadLocal工具类
自定义ThreadLocal package concurrent; import java.util.HashMap; import java.util.Map; /** * @author alo ...
- java类的初始化
转载:http://blog.csdn.net/moreevan/article/details/6968718 我们知道一个类(class)要被使用必须经过装载,连接,初始化这样的过程.下面先对这三 ...