ZOJ 2110 Tempter of the Bone
Tempter of the Bone
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 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
The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), 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 0'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
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
NO
YES
普通的搜索题,写完以后不幸TLE
之后看题解,发现这道题作为一道教程(完全没看)题,专门讲剪枝…… WTF!
于是加了个剪枝过了。300+ms,实际上可以各种花式剪枝把时间压到80ms,但是看写博客的时间就知道我为什么不想多写
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
char map[20][20];
int mx[5]={0,-1,0,1,0},
my[5]={0,0,1,0,-1};
int n,m,Time;
int tx,ty;
int flag=0;
void dfs(int x,int y,int t){
if(x==tx && y==ty && t==Time){
flag=1;
return;
}
if(map[x][y]=='X')return;
//
if(t>=Time)return;//剪枝
int temp=(Time-t)-fabs(x-tx)-fabs(y-ty);
if(temp<0 ||temp %2)return; //
int i;
for(i=1;i<=4;i++){
int nx=x+mx[i];
int ny=y+my[i];
if(nx>=0 && nx<n && ny>=0 && ny<m)
// if(map[nx][ny]!='X')
{
map[x][y]='X';
dfs(nx,ny,t+1);
if(flag)return;
map[x][y]='.';
}
}
return;
}
int main(){
while(scanf("%d%d%d",&n,&m,&Time)!=EOF)
{
flag=0;
if(n==0 && m==0 && Time==0)break;
int i,j;
int xx,yy;
for(i=0;i<n;i++){
scanf("%s",map[i]);
for(j=0;j<m;j++){
if(map[i][j]=='S')xx=i,yy=j;
if(map[i][j]=='D')tx=i,ty=j;//目标点
}
}
dfs(xx,yy,0);
if(flag==1)printf("YES\n");
else printf("NO\n");
}
return 0;
}
ZOJ 2110 Tempter of the Bone的更多相关文章
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- zoj 2110 Tempter of the Bone (dfs)
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- ZOJ 2110 Tempter of the Bone(DFS)
点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- 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 ...
- 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 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- Jenkins学习六:修改Jenkins用户的密码
很多时候在使用jenkins的时候忘记密码了,遇到这种情况,可以看看下面的讲解. Jenkins专有用户的数据存放在JENKINS_HOME/users目录.users目录的结构你一看就懂.users ...
- where,having与 group by连用的区别
select 列a,聚合函数 from 表名 where 过滤条件 group by 列a having 过滤条件 group by 字句也和where条件语句结合在一起使用.当结合在一起时,wher ...
- Nginx反向代理+负载均衡简单实现(https方式)
背景:A服务器(192.168.1.8)作为nginx代理服务器B服务器(192.168.1.150)作为后端真实服务器 现在需要访问https://testwww.huanqiu.com请求时从A服 ...
- mysql数据库误删除后的数据恢复操作说明
在日常运维工作中,对于mysql数据库的备份是至关重要的!数据库对于网站的重要性使得我们对mysql数据的管理不容有失!然后,是人总难免会犯错误,说不定哪天大脑短路了来个误操作把数据库给删除了,怎么办 ...
- 研:手势与眼动相结合-手势SDK的整合
Leap提供了SDK.但是整合有很多的问题,写博客记录一下: 写一个类:SampleListener.cpp以及头文件SampleListener.h. 这里主要碰到的问题是找不到以及冲突问题: 这里 ...
- Caffe学习系列(12):训练和测试自己的图片
学习caffe的目的,不是简单的做几个练习,最终还是要用到自己的实际项目或科研中.因此,本文介绍一下,从自己的原始图片到lmdb数据,再到训练和测试模型的整个流程. 一.准备数据 有条件的同学,可以去 ...
- windows下怎么打开psql命令
你是直接执行的psql.exe吧? 那么需要加入数据库位置等一些参数的.Windows系统下,PostgreSQL有提供一个命令行脚本runsql.bat, 在安装目录的scripts文件夹中,一般是 ...
- 实验箱FPGA部分测试报告及A8与FPGA链接测试报告
其实,我一开始还以为实验箱不会有什么问题只是让我们多学习东西才做这个测试的,结果发现还真的有不少问题. 1.实验准备部分 安装驱动时,win10系统无法正确安装usb-blaster Windows ...
- .NET MVC框架中控制器接收参数的四种方式
1.通过路由中的配置的参数名字直接接收(要求:两者同名) routes.MapRoute( name: "Default", ...
- Git.Framework 框架随手记--ORM条件组合
在上一篇<Git.Framework 框架随手记--ORM新增操作>中简单记录了如何对数据进行删除和修改,其用法都非常简单,在文章中提到了Where()方法,本文将详述Where() 等条 ...