杭电(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 ...
随机推荐
- Python开发利器PyCharm 2.7附注册码
PyCharm 2.7 下载 http://download.jetbrains.com/python/pycharm-2.7.2.exe 激活注册 user name:EMBRACE key: 14 ...
- vs code golang代码自动补全
“go.useCodeSnippetsOnFunctionSuggest”: true 文件-->首选项--->设置--->用户设置 添加下行:然后就可以自动补全了,包括() “go ...
- Python 38 初识数据库
数据库 1.什么是mysql,什么是数据库? 文件处理就可以将数据永久存储 问题 1.管理不方便 2.文件操作效率问题 3.一个程序不太可能仅运行在同一台电脑上 提高计算机性能的方式 1.垂直扩展 ...
- python 端口扫描程序
#! /usr/bin/env python3 #-*- coding:utf-8 -*- import socket import threading OPEN_COUNT = 0 lock = t ...
- centos 修改网卡信息命令
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- hbase无法启动,The node /hbase is not in ZooKeeper
问题详细描述如下: 2016-12-09 15:10:39,160 ERROR [org.apache.hadoop.hbase.client.ConnectionManager$HConnectio ...
- 生成jsp验证码的代码详解(servlet版)
package util; import java.util.*; import java.io.*; import java.awt.*; import java.awt.image.*; impo ...
- 《CSS Mastery》读书笔记(2)
第二章 目标的样式 要用CSS样式化一个HTML元素,必须要定位一个元素, CSS的选择器就是这样的手段. 这章中,你要学到的 • Common selectors 普通选择器 • Advanc ...
- JavaScript的基本语法(一)
一.常用的表单元素有: 文本框(text). 密码框(password). 多行文本框(<textarea>) 单选按钮(radio). 复选框(checkbox). 列表框(<se ...
- Python3编写自动签到服务程序
公司加班的餐补需要登录网站签到领取,有时候会忘记,于是自己用Python写了小程序来自动签到.刚开始只是做了自己用,直接写的黑框程序,后来给同事用,就打包成exe.再后来有人说要写成window服务会 ...