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 直道找到满足条件的路径 ...
随机推荐
- javascript和python取dict字典对象的不同
dict1={"a":1,"b":2,"22a":44} JS: dict1.a 和 dict1["a"]都可以 pyt ...
- Windows + IIS 环境部署Asp.Net Core App
环境:Windows Server 2012, IIS 8, Asp.Net Core 1.1. 不少人第一次在IIS中部署Asp.Net Core App的人都会遇到问题,会发现原来的部署方式无法运 ...
- BigDecimal 小数 浮点数 精度 财务计算
简介 float和double类型的使用局限: 单精度浮点型变量float可以处理6~7位有效数,双精度浮点型变量double可以处理15~16位有效数,在实际应用中,如果需要对更大或者更小的数进行运 ...
- JAVA输出指定目录下的子目录和子文件
题目:给定一个目录,要求输出这个目录下面的子目录和子文件 逻辑: 先判断给定的是不是一个合法的目录,如果不是,则提示给定错误 如果是目录,那么使用File.listFile()获得这个目录下文件名的数 ...
- eclipse 使用Maven deploy命令部署构建到Nexus上 【二】
http://blog.csdn.net/jun55xiu/article/details/43051627
- Realm Swift
Realm Swift 当前这个翻译,主要是方便我自己查阅api,有非常多地方写的比較晦涩或者没有翻译,敬请谅解 version 0.98.7 官方文档 參考文献 Realm支持类型 String,N ...
- 如何使用Octave 在Ubuntu上科学处理音频
Octave 是一个类似于 Linux 上的 Matlab 的软件,它拥有数量众多的函数和命令,支持声音采集.记录.回放以及音频信号的数字化处理,用于娱乐应用.研究.医学以及其它科学领域.在本教程中, ...
- 利用js_API 执行对html文档元素的属性的CRUD操作
转自:http://my.oschina.net/felay/blog/303470 <!DOCTYPE html> <html> <head> <meta ...
- postgresql 内存分配
postgresql的内存分配主要由shared_buffers.temp_buffers.work_mem.maintenance_work_mem参数控制. shared_buffers又可以叫做 ...
- 自己的一个js库
https://github.com/sqqihao/nono_framework.git 持续更新,慢慢写着,这样才能成长