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//一个很好理解剪枝思想的博客 ...
随机推荐
- asp.net button浏览器端事件和服务器端事件
OnClientClick:触发浏览器端的响应,OnClick触发服务器端响应; 在服务器aspx.cs脚本中设置按钮属性: this.btnTest.Attributes["OnClick ...
- java高并发下的数据安全
高并发下的数据安全 我们知道在多线程写入同一个文件的时候,会存现“线程安全”的问题(多个线程同时运行同一段代码,如果每次运行结果和单线程运行的结果是一样的,结果和预期相同,就是线程安全的).如果是My ...
- Xcode9 新功能
翻译: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/WhatsNewXcod ...
- python重要模块之subprocess模块
python重要模块之subprocess模块 我们经常要通过python去执行系统的命令或者脚本,系统的shell命令是独立于你的python进程之外的,每执行一条命令,就相当于发起了一个新的进程, ...
- js之购物车案例
这里主要提供思路: 一共两个页面通过原生来实现,我们需要对cookie进行封装. 在商品列表页,我们将点击添加的商品放入一个对象中,而后将该对象放入数组中,一个对象可以说就是一个商品.在购物车页面 ...
- 在notepad++中插件安装的办法
在notepad++中插件安装的办法新版的notepad++去掉了一个叫做插件管理工具的插件.这就导致我们不能通过界面去安装notepad++的一些比较方便的插件了.本文通过手动安装插件管理工具和ft ...
- 监听器(Listener)学习(一)
一.监听器介绍 1.1.监听器的概念 监听器是一个专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动.监听器其实就是一个实现特定接口的普通 ...
- 使用jdbc对数据库增删改查(Mysql为例)
一.statement对象介绍 Statement对象的executeUpdate方法,用于向数据库发送增.删.改的sql语句,executeUpdate执行完后,将会返回一个整数. Statemen ...
- 使用python处理selenium中的frame切换问题
# iframe有name或id值 self.driver.switch_to.frame('iframe-name-id') # iframe没有name或id值 xf = self.driver. ...
- 同一台电脑上装两个或两个以上的tomcat服务器
1.下载免安装版tomcat,解压成tomcat1.tomcat2: 2.修改tomcat2中conf下server.xml文件如下: <Server port="8005" ...