hduoj---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): 55812 Accepted Submission(s): 15052
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.
'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.
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
YES
#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的更多相关文章
- 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 直道找到满足条件的路径 ...
随机推荐
- Python3.6学习笔记(四)
错误.调试和测试 程序运行中,可能会遇到BUG.用户输入异常数据以及其它环境的异常,这些都需要程序猿进行处理.Python提供了一套内置的异常处理机制,供程序猿使用,同时PDB提供了调试代码的功能,除 ...
- 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 ...
- ldap服务器OpenLDAP安装使用
OpenLDAP 是 LDAP 协议的一个开源实现.LDAP 服务器本质上是一个为只读访问而优化的非关系型数据库.它主要用做地址簿查询(如 email 客户端)或对各种服务访问做后台认证以及用户数据权 ...
- Android UI-底部旋转菜单栏
以前都是说每逢佳节倍思亲,现在的工作状态是每到周末倍亲切,年底真的是加班加的没完没了的,也没时间写博客,也没时间学习,周末闲来无事看到一个比较有意思的旋转菜单,没事自己实战了一下感觉还不错,代码倒是没 ...
- QlikView图表显示同比数据
数据准备例如以下: SalesData: LOAD Num(ID) as ID, Date(Date) as Date, Month, Num(Year) as Year, Num(Sales) as ...
- IIS-设置session时间
session会话类型
- [Unity-6] GameObject有时候渲染不出来
问题描写叙述:在做游戏的过程中遇到了这样一个问题.一个怪物,假设让他出如今屏幕的中央是没问题的,可是让他出如今屏幕的边缘的位置发现他没有出现. 问题原因:经过检查发现,我给这个GameObject加入 ...
- 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 ...
- 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效能相对硬盘 ...
- 在Ubuntu 桌面版 12.04 LTS安装并运行SSH
第一步:安装openssh-server #sudo apt-get install openssh-server 第二步:查看ssh服务是否已经运行,执行 #ps -e | grep ssh 执行完 ...