杭电(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 ...
随机推荐
- css定位、position与float同时使用的情况
一.css定位 CSS 有三种基本的定位机制:普通流.浮动和绝对定位. 1.普通流:未专门指定的元素都在普通流中定位,position:static/relative;和float:none;也在普通 ...
- C - Gravity Flip
Problem description Little Chris is bored during his physics lessons (too easy), so he has built a t ...
- A - Team
Problem description One day three best friends Petya, Vasya and Tonya decided to form a team and tak ...
- MTK刷机工具Flash_Tool部分4032错误解决办法
MTK刷机工具Flash_Tool部分4032错误解决办法 先说明一点,这个办法不是万能的,我测试解决了以下两种情况下的4032: 1.本来正常的开发板,因为一次刷机失败后就一直变4032了 2.新开 ...
- Azure Service Bus
Azure Service Bus 是类似Rabbit的一个队列的应用. 找了两个基本的教程 First(但是这个,没有写怎么去链接账户) Sec:这个有 Third(讲的也很好) Windo ...
- dubbo之隐式参数
隐式参数 可以通过 RpcContext 上的 setAttachment 和 getAttachment 在服务消费方和提供方之间进行参数的隐式传递. 在服务消费方端设置隐式参数 setAttach ...
- JAVA 构建使用 Native 库
Java 使用Native文件,一般分解为下面几个步骤: 在Java代码中使用native关键字声明一个本地方法 运行javah,获得包含该方法声明的C语言头文件(使用jni编程中的C函数名通常是相关 ...
- (转)Openlayers 2.X加载高德地图
http://blog.csdn.net/gisshixisheng/article/details/44853881 概述: 前面的有篇文章介绍了Openlayers 2.X下加载天地图,本节介绍O ...
- 01 DOS常用命令
有时候没有可视化窗口,命令行对文件进行操作更方便快捷 cmd 命令弹出 dir 查看当前所在目录下的文件 ctrl+c 退出 \a 显示隐藏文件 cd /改变到根目录 dir /a 显示隐藏文件 di ...
- 使用JAVA写一个简单的日历
JAVA写一个简单的日历import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateF ...