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//一个很好理解剪枝思想的博客 ...
随机推荐
- ElasticSearchRepository和ElasticSearchTemplate的使用
Spring-data-elasticsearch是Spring提供的操作ElasticSearch的数据层,封装了大量的基础操作,通过它可以很方便的操作ElasticSearch的数据. 版本说明 ...
- Nodejs操作MongoDB数据库示例
//mongodb_demo.js /** cnpm install mongodb */ var MongoClient = require('mongodb').MongoClient; var ...
- dyld: lazy symbol binding failed: Symbol not found: ___sincosf_stret
This is the error I get: dyld: lazy symbol binding failed: Symbol not found: ___sincosf_stret Refere ...
- zookeeper 学习命令
ls /TianheSoft/nodesls /TianheSoft/nodes/localhost_2181-0000000000ls /TianheSoft/propsls /TianheSoft ...
- centos7最小化安装后配置笔记
一.安装wget(步骤2备用) yum install wget -y 二.切换yum源为阿里云 备份旧源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum ...
- BootStrap FileInput 插件实现多文件上传前端功能
<!DOCTYPE html> <html> <head> <title>文件上传</title> <meta charset=&qu ...
- Uoj 22 外星人
Uoj 22 外星人 注意到一个数只有 \(\%\) 了小于等于自己的数时,才可能有变化,否则可以随意安排,不会对最后最优解造成影响. 用 \(f[x]\) 表示给一个数 \(x\) ,仅用 \(a[ ...
- ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存
分享 最近在公司成功落地了一个用ASP.NET Core 开发前台的CMS项目,虽然对于表层的开发是兼容MVC5的,但是作为爱好者当然要用尽量多的ASP.NET Core新功能了. 背景 在项目开发的 ...
- spring注解实现业务层事务管理,当业务层自调用时,事务失效问题解决
前些日子一朋友在需要在目标对象中进行自我调用,且需要实施相应的事务定义,且网上的一种通过BeanPostProcessor的解决方案是存在问题的.因此专门写此篇帖子分析why. 1.预备知识 aop概 ...
- WPF中Grid实现网格,表格样式通用类(转)
/// <summary> /// 给Grid添加边框线 /// </summary> /// <param name="grid"></ ...