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. 混沌数学之Henon吸引子

    Henon吸引子是混沌与分形的著名例子. 相关软件:混沌数学及其软件模拟相关代码: // http://wenku.baidu.com/view/d51372a60029bd64783e2cc0.ht ...

  2. URAL 1698

    题目大意:统计位数不大于n的自守数的个数. KB     64bit IO Format:%I64d & %I64u 数据规模:1<=n<=2000. 理论基础: 自守数:参见链接 ...

  3. .NET-"/"应用程序中的服务器错误

    当出现这个问题的时候,就在web.config文件中加上代码:<customErrors mode="Off"/> 然后重新访问站点就能看到问题所在了,例如我的错误显示 ...

  4. 独立开发人员低成本推广APP的18条技巧

    导语:知道并不等于运行,有些最主要的推广方法往往会被忽略.这些,是自国外开发人员总结出的这18条经验. 如今市面上充满了大牌子大公司和大制作的手机游戏,常常有游戏花300万成本开发,然后再花2000万 ...

  5. [Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix

    // Code goes here function countNegative (M, n, m) { count = ; i = ; j = m - ; && i < n) ...

  6. [Node.js]33. Level 7: Persisting Questions

    Let's go back to our live-moderation app and add some persistence, first to the questions people ask ...

  7. JavaScript高级程序设计(第3版)学习笔记·第8章——浏览器对象模型BOM

    转自:http://www.shaoqun.com/a/43768.aspx 访问和操作浏览器窗口的模型称为浏览器对象模型BOM(Browser Object Model),但习惯上是把所有针对浏览器 ...

  8. rapidxml 解析修改内存的值

    1.使用rapidxml解析的时候,也就是 调用xmlDoc.parse<0>(xmlContent),特别注意,rapidxml会修改内存的值,把右尖括号>修改为'\0',因此特别 ...

  9. CAD批量合并文件

    要求:将整饰完成504幅单独的宗地图合并成一张总图,合并后,去掉其他要素,只保留毕合的权属线. 解决: 1.合并dwg文件,除了手工粘贴复制外,最先想到的是插入块,即用Insert命令插入,测试结果可 ...

  10. sqlplus的使用

    1.连接数据库 sqlplus / as sysdba 2.连接到远程数据库 sqlplus 用户名/密码@服务命名 3.遇到&会当成变量,一般是不需要的,可以关掉 SQL> set d ...