Tempter of the Bone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 55812    Accepted Submission(s): 15052

Problem Description
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
 
Author
ZHANG, Zheng
 
Source
搜索题:dfs深度优先搜索、、、、
代码:
 #include<stdio.h>
#include<string.h>
#include<math.h>
int n,m,ex,ey,t;
bool success;
char maze[][]; //考虑到要加边
/*
stx ---->开始x坐标
sty ---->开始y坐标
dt ---->花掉时间
*/ void dfs(int stx,int sty,int dt )
{
/*
超过规定时间,超边都表示无法完成任务
*/
if(stx<=||stx>n||sty<=||sty>m) /* 可以加边处理的*/
return ;
if(stx==ex&&sty==ey&&dt==t)
success=true;
if(success) return ;
int temp=(t-dt)-abs(ex-stx)-abs(ey-sty);
if(temp<||temp&) //奇偶剪枝
return ;
/*
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
无论是从o 开始还是从1开始,
都是 0--->1 或者1--->0 都是奇数步
0-->0 , 1--->1 都是偶数步
*/
//然后是对上下左右的搜索
if(maze[stx][sty+]!='X') //向右搜索
{
maze[stx][sty+]='X'; //见进入口堵上
dfs(stx,sty+,dt+);
maze[stx][sty+]='.';
} if(maze[stx+][sty]!='X') //向下搜索
{
maze[stx+][sty]='X'; //见进入口堵上
dfs(stx+,sty,dt+);
maze[stx+][sty]='.';
}
if(maze[stx][sty-]!='X') //向左搜索
{
maze[stx][sty-]='X'; //见进入口堵上
dfs(stx,sty-,dt+);
maze[stx][sty-]='.';
}
if(maze[stx-][sty]!='X') //向上搜索
{
maze[stx-][sty]='X'; //见进入口堵上
dfs(stx-,sty,dt+);
maze[stx-][sty]='.';
}
return ;
} int main()
{
int stx,sty,wall;
while(scanf("%d%d%d",&n,&m,&t),n+m+t)
{
getchar();
wall=; //统计障碍物的个数 每次输入清零
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%c",&maze[i][j]);
if(maze[i][j]=='S')
{
stx=i; // 标注开始的x轴的位置
sty=j; // 标注开始的y轴的位置
}
else
if(maze[i][j]=='D')
{
ex=i; // 标注结束的x轴的位置
ey=j; // 标注结束的y轴的位置
}
else if(maze[i][j]=='X')
{
wall++;
}
}
getchar();
}
success=false;
maze[stx][sty]='X'; //堵住入口
if( n*m-wall<=t ) //因为只有在t时刻door 才打开
printf("NO\n");
else
{
dfs(stx,sty,);
if(success)
printf("YES\n");
else
printf("NO\n");
}
}
return ;
}

hduoj---Tempter of the Bone的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. 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 ...

  6. 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 ...

  7. Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

随机推荐

  1. Python3.6学习笔记(四)

    错误.调试和测试 程序运行中,可能会遇到BUG.用户输入异常数据以及其它环境的异常,这些都需要程序猿进行处理.Python提供了一套内置的异常处理机制,供程序猿使用,同时PDB提供了调试代码的功能,除 ...

  2. Top N之MapReduce程序加强版Enhanced MapReduce for Top N items

    In the last post we saw how to write a MapReduce program for finding the top-n items of a dataset. T ...

  3. ldap服务器OpenLDAP安装使用

    OpenLDAP 是 LDAP 协议的一个开源实现.LDAP 服务器本质上是一个为只读访问而优化的非关系型数据库.它主要用做地址簿查询(如 email 客户端)或对各种服务访问做后台认证以及用户数据权 ...

  4. Android UI-底部旋转菜单栏

    以前都是说每逢佳节倍思亲,现在的工作状态是每到周末倍亲切,年底真的是加班加的没完没了的,也没时间写博客,也没时间学习,周末闲来无事看到一个比较有意思的旋转菜单,没事自己实战了一下感觉还不错,代码倒是没 ...

  5. QlikView图表显示同比数据

    数据准备例如以下: SalesData: LOAD Num(ID) as ID, Date(Date) as Date, Month, Num(Year) as Year, Num(Sales) as ...

  6. IIS-设置session时间

    session会话类型

  7. [Unity-6] GameObject有时候渲染不出来

    问题描写叙述:在做游戏的过程中遇到了这样一个问题.一个怪物,假设让他出如今屏幕的中央是没问题的,可是让他出如今屏幕的边缘的位置发现他没有出现. 问题原因:经过检查发现,我给这个GameObject加入 ...

  8. Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci

      Error:(1, 0) The android gradle plugin version 3.0.0-alpha1 is too old, please update to the lates ...

  9. PU-bound(计算密集型) 和I/O bound(I/O密集型)

    转载:https://blog.csdn.net/q_l_s/article/details/51538039 I/O密集型 (CPU-bound) I/O bound 指的是系统的CPU效能相对硬盘 ...

  10. 在Ubuntu 桌面版 12.04 LTS安装并运行SSH

    第一步:安装openssh-server #sudo apt-get install openssh-server 第二步:查看ssh服务是否已经运行,执行 #ps -e | grep ssh 执行完 ...