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暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
随机推荐
- linux下合并pdf
使用Gost Script和 PDFtk运行如下命令: #gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Linuxidc.pdf -dBATCH *.p ...
- Excel教程(4) - 数据库函数
DAVERAGE 用途:返回数据库或数据清单中满足指定条件的列中数值 的平均值. 语法:DAVERAGE(database,field,criteria) 参数:Database 构成 ...
- $pull
$pull 删除所有匹配的文档,不仅仅只是删除一个. db.test.insert( {"todo":["dishes","laundry" ...
- OC类的本质及分类
(一)类的本质 类对象(class object)与实例对象(instance object) 类本身也是一个对象,是class类型的对象,简称“类对象”. 在/usr/include/objc/ob ...
- WEB组件 开发 (未完成 4-13)
整理自真阿当的阿当大话西游之WEB组件,课件中的代码下载. 14. 抽出widget类 组件分两大类: utility(大部分与UI无关的组件) 和 widget(应用层,大部分与UI相关的,日历组件 ...
- 如何通过Maven的Jetty插件运行Web工程
首先建议使用jetty9,因为据官方文档显示,Jetty 7 and Jetty 8 are now EOL (End of Life),如下.但是由于项目使用的版本一般都比较低,这里以jetty8为 ...
- wordpress建站过程3——header.php
header.php中包含了一个页面的页头,也就是其他页面中重复出现的部分,包括用户登陆/登陆后显示的文字,导航条,网页logo,有的还包括轮播图. 下面就简单的贴上一个文件吧. <!DOCTY ...
- ios简单更改系统TabBar的高度
- (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGRect frame = self.tabBar.frame; fra ...
- 48、tensorflow入门二,线性模型的拟合
import tensorflow as tf import numpy as np#生成2维的100个0-1的随机数 x_data = np.float32(np.random.rand(2,100 ...
- hdu_2842_Chinese Rings(矩阵快速幂)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题意:解开第k个环需要先解开前(k-2)个环,并留有第(k-1)环.问解开n环最少需要几步. 题 ...