hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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 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 ( < N, M < ; < T < ), 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 '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 S.X.
..X.
..XD
.... S.X.
..X.
...D Sample Output
NO
YES Author
ZHANG, Zheng Source
ZJCPC2004 Recommend
JGShining
#include <iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int sx,sy,ex,ey;
int n,m;
int flag;
int d[][]={,,,,,-,-,};
char map[][];
void dfs(int x,int y,int t)
{
//cout<<x<<" "<<y<<" "<<t<<endl;
if(flag==)return;
if(t<sqrt(float((ex-x)*(ex-x)+(ey-y)*(ey-y)))||(t-abs(ex-x)+abs(ey-y))%)return;
else if(t==)
{
if(x==ex&&y==ey){flag=;return;}
else
return;
}
else
{
for(int i=;i<;i++)
{
int nx = x+d[i][];
int ny = y+d[i][];
if(nx>&&nx<=n&&ny>&&ny<=m&&(map[nx][ny]=='.'||map[nx][ny]=='D'))
{
map[nx][ny]='X';
dfs(nx,ny,t-);
map[nx][ny]='.';
}
}
}
return ;
}
int main()
{
int t,num;
char str[];
while(scanf("%d%d%d",&n,&m,&t),n||m||t)
{
num=;
for(int i=;i<=n;i++)
{
scanf("%s",str);
for(int j=;j<=m;j++)
{
map[i][j]=str[j-];
if(map[i][j]=='S')sx=i,sy=j;
else if(map[i][j]=='D')ex=i,ey=j,num++;
else if(map[i][j]=='.')num++;
}
} flag=;
if(num>=t)
dfs(sx,sy,t);
if(flag==)
printf("NO\n");
else
printf("YES\n");
}
return;
}
hdu1010 Tempter 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 ...
- Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- Hdu1010Tempter of the Bone 深搜+剪枝
题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’:判断能否从S正好走t步到D. 题解:dfs,奇偶性减枝,剩余步数剪枝. ps:帮室友Debug的题:打错了两个字 ...
- HDU1010 --- Tempter of the Bone(dfs+剪枝)
小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t ...
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
随机推荐
- MySQL笔记之多表
貌似很久不写博客了,趁着项目刚完结,记录一下这段时间了解到的一些认识,或许有些地方理解的还不够到位,看到的希望能不吝赐教. 外键 概念 与索引的关系 写法 查询 一对多多对一查询 多对多查询 插入 多 ...
- 基于EasyNVR实现RTSP/Onvif监控摄像头Web无插件化直播监控
前言 随着互联网的发展,尤其是移动互联网,基于H5.微信的应用越来越多,企业也更多地想基于H5.微信公众号来快速开发和运营自己的产品,那么传统的安防IPC所输出的各种RTSP.GB28181.SDK视 ...
- IOS 的本地通知
IOS 的本地通知 - (void)viewDidLoad { [super viewDidLoad]; UILocalNotification* localNotification = [[UILo ...
- 7.翻转句子中单词的顺序[ReverseWordOrderInSentence]
[题目] 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“I am a student.”,则输出“stud ...
- Intro to DBSCAN
DBSCAN Density-Based Spatial Clustering of Application with Noise It can discover cluster of arbitra ...
- 2019ICPC南昌邀请赛网络赛 I. Max answer (单调栈+线段树/笛卡尔树)
题目链接 题意:求一个序列的最大的(区间最小值*区间和) 线段树做法:用单调栈求出每个数两边比它大的左右边界,然后用线段树求出每段区间的和sum.最小前缀lsum.最小后缀rsum,枚举每个数a[i] ...
- 每天一个linux命令(文件操作):【转载】whiereis命令
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度非 ...
- spring mvc 思想
目录 一.前言 二.spring mvc 核心类与接口 三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说 ...
- 【angularJS】启动(bootstrap)机制
Angular的启动分为手动和自动两种. 自动启动 定义模块的例子中,采用的就是自动的方式:通过内置的指令ngApp 来指定启动时加载的模块.<html ng-app="myApp&q ...
- liunx系统环境下,爆出该错误"org.eclipse.wst.validation" has been removed解决办法
导出maven工程遇到的问题,"org.eclipse.wst.validation" has been removed,还以为是工程本身的问题,后来发现是eclipse的问题. ...