杭电(hdu)ACM 1010 Tempter of the Bone
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90328 Accepted Submission(s): 24554
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.
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.
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
NO
YES
!
。。
#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
using namespace std; int N,M,T,escape,wall;
int starti,startj,endi,endj;
char map[101][101];
int v[101][101];
int dir[4][2]={1,0,-1,0,0,1,0,-1};
void dfs(int x,int y,int time)
{
if(abs(endi-x)+abs(endj-y)>T-time)return;
if((abs(endi-x)+abs(endj-y))%2!=(T-time)%2)return;
if(x==endi&&y==endj&&time==T)escape=1;
if(escape==1)return;
for(int i=0;i<=3;i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
if(xx>=1&&xx<=N&&yy>=1&&yy<=M&&map[xx][yy]!='X'&&v[xx][yy]==0)
{
v[xx][yy]=1;
dfs(xx,yy,time+1);
v[xx][yy]=0; //回溯
}
}
return;
}
int main()
{
while(cin>>N>>M>>T,N||M||T)
{
wall=0;
memset(v,0,sizeof(v));
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
{
cin>>map[i][j];
if(map[i][j]=='S')
{
starti=i;
startj=j;
}
else if(map[i][j]=='X')
{
wall++;
}
else if(map[i][j]=='D')
{
endi=i;
endj=j;
}
}
v[starti][startj]=1;
escape=0;
dfs(starti,startj,0);
if(N*M-wall<T){cout<<"NO"<<endl;continue;}
if(escape==1)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
杭电(hdu)ACM 1010 Tempter of the Bone的更多相关文章
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 杭电 HDU ACM Milk
Milk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
欢迎"热爱编程"的高考少年--报考杭州电子科技大学计算机学院 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memor ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- 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 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
- 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 ...
随机推荐
- Flink之流处理理论基础
目录 Introduction to Stateful Stream Processing Traditional Data Infrastructures Stateful Stream Proce ...
- Django day15 (二) csrf的 跨站请求伪造 与 局部禁用 , 局部使用
一: csrf 的跨站请求伪造 二: csrf 的局部禁用 , 局部使用
- 编写linux 命令行实用工具 shell命令
今天我想以带着问题的方法学习新的技术. 问题1: 编写一个命令 语法: command options path expressions
- RabbitMQ 官方NET教程(五)【Topic】
在上一个教程中,我们改进了我们的日志记录系统.我们使用direct类型转发器,使得接收者有能力进行选择性的接收日志,,而非fanout那样,只能够无脑的转发 虽然使用direct类型改进了我们的系统, ...
- 【原创】.Net 微信 JS-SDK图片、语音上传接口的实现(MVC)-(一 、上传图片)
前段时间在做一个微信的项目,遇到了一个上传图片的问题,花了一下午,解决了这个问题,然后把总结出来的代码,分享了出来. 最近又有一个图片+语音的功能, 更是蛋疼, 本次采用的不是File文件上传,然后转 ...
- ArcGIS API For Android Errors汇总
API客户端异常错误的发生通常是由于不正确的方法参数,对象状态依赖,或网络条件. //*******推荐使用方法,按下Ctrl+F搜索错误代码,再查看与代码对应的解释.********// ArcGI ...
- dubbo之上下文信息
上下文信息 上下文中存放的是当前调用过程中所需的环境信息.所有配置信息都将转换为 URL 的参数,参见 schema 配置参考手册 中的对应URL参数一列. RpcContext 是一个 Thread ...
- AI: DL方法与问题空间探索
所谓问题的解决是生存参数空间的一种状态转移到另外一种状态,而目的状态恰好是主体所希望的.完成这种转换的一系列脚本变化过程叫做场景序列,也叫通路.驱动这一些列场景转换的主体参与过程,被称为主动执行.而主 ...
- 11.02 跳过表中n行
select x.enamefrom (select a.ename,(select count(*)from emp bwhere b.ename <=a.ename) as rnfrom e ...
- Objective-C类成员变量深度剖析--oc对象内存模型
目录 Non Fragile ivars 为什么Non Fragile ivars很关键 如何寻址类成员变量 真正的“如何寻址类成员变量” Non Fragile ivars布局调整 为什么Objec ...