Tempter of the Bone
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.
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.
case, print in one line "YES" if the doggie can survive, or "NO"
otherwise.
..X.
....
#include
#include
#include
#include
#define maxn 205
using namespace std;
int visit[maxn][maxn];//这个是记录步数的不是记录走没走的不能用布尔型
char mapn[maxn][maxn];
int n,m,t,direction[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int sx,sy,dx,dy;
bool flag;
void dfs(int x,int y,int time)
{
if(x<1||x>n||y<1||y>m)//边界
return;
if(flag==1)
return;
if(x==dx&&y==dy&&time==t)//找到D了
{
if(time=t)
flag=1;
return;
}
int
temp=(t-time)-abs(x-dx)-abs(y-dy);//奇偶性剪枝
if(temp<0||temp&1) return;
for(int
i=0;i<4;i++)
{
int x1=x+direction[i][0];
int y1=y+direction[i][1];
if(mapn[x1][y1]!='X')
{
mapn[x1][y1]='X';
dfs(x1,y1,time+1);
mapn[x1][y1]='.';//不满足条件的话就返回
}
}
return;
}
int main()
{
int
s=0;
//freopen("in.txt", "r", stdin);
while(~scanf("%d%d%d\n",&n,&m,&t)&&n&&m&&t)
{
flag=s=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%c",&mapn[i][j]);
if(mapn[i][j]=='S')
{
sx=i;
sy=j;//狗的位置
}
if(mapn[i][j]=='D')
{
dx=i;
dy=j;//门的位置
}
if(mapn[i][j]=='X')
s++;
}
scanf("\n");
}
mapn[sx][sy]='X';
memset(visit,0,sizeof(visit));
//for(int i=1;i<=n;i++)
//{
// for(int
j=1;j<=m;j++)
// {
//
printf("%c",mapn[i][j]);
// }
//
printf("\n");
//}
if (n*m-s<=t)//提前判断t过大的情况避免再去搜
{
printf("NO\n");
continue;
}
dfs(sx,sy,0);
//printf("最少走 %d 秒 有 %d 秒\n",ans,t);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
Tempter of the Bone的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
随机推荐
- Manacher详解
之前的字符串题解中对Manacher的思想进行了简略的介绍,在这篇文章中,我将会详细的将这个算法的初衷和具体实现理论进行解释.声明一点,这是我个人的理解,可能有不全面之处,望多包涵.在之前的几篇文章中 ...
- angular之$watch方法详解
在$apply方法中提到过脏检查,首先apply方法会触发evel方法,当evel方法解析成功后,会去触发digest方法,digest方法会触发watch方法. (1)$watch简介 在diges ...
- Nginx学习——Nginx简单介绍和Linux环境下的安装
一:Nginx的简介 百科百科:Nginx Nginx 是一个俄罗斯的哥们开发的,并将其进行了开源. Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器, ...
- 关于 HashTable
hashTable 的一些认识: 底层使用散列表,存贮键值对,键值非null 使用synchronize 保证线程安全 (线程安全) ■全局变量 //The hash table data. //底层 ...
- 将childNodes返回的数据转化维数组的方法
//将childNodes返回的数据转化为数组的方法 function convertToArray(nodes){ var array=null; try{ array=Array.prototyp ...
- JS或jQuery实现一组复选框的全选和取消全选?
//1.JS方式实现:checkbox 全选/取消全选 var isCheckAll = false; function swapCheck() { if (isCheckAll) { ...
- 初学者易上手的SSH-struts2 01环境搭建
首先,SSH不是一个框架,而是多个框架(struts+spring+hibernate)的集成,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. 集成SSH框 ...
- LeetCode-2 Keys Keyboard
package Classify.DP.Medium; import org.junit.jupiter.api.Test; /** Initially on a notepad only one c ...
- zoj3321 circle floyd 最小生成树
Circle 断一个图是否是一个环. 思路:必有m==n,那么我们用n-1条边能够生成一棵树(即是所有点联通,则用floyd即可),然后看最后一条边的两个点是否是单边(度为一)即可 . #includ ...
- 学习笔记之09小练习题(js:从小到大输出三个任意数,查成绩,相亲题,查体重,一元二次方程求根)
<script type="text/javascript"> /*第一题.输入三个整数,x,y,z,最终以从小到大的方式输出. 注意小点:1 字符串的拼接是用+,数学 ...