Tempter of the Bone

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

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
 
 #include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
char map[][];
bool vis[][];
int dx[]={,,-,},dy[]={,-,,};
int n,m,t;
int sx,sy,ex,ey;
bool flag;
bool dfs(int x,int y,int tim)
{
if(flag) return ;
if(x<||y<||x>=n||y>=m||vis[x][y]==||tim>t||map[x][y]=='X')
return ;
if(tim<t&&map[x][y]=='D') return ;
int w=abs(x-ex)+abs(y-ey);
if(t-tim<w) return ;
int tem=w-abs(t-tim);
if(tem>||tem%) return ;
if(tim==t&&map[x][y]=='D') {flag=;return ;}
for(int i=;i<;i++)
{
vis[x][y]=;
int nx=x+dx[i];
int ny=y+dy[i];
dfs(nx,ny,tim+);
vis[x][y]=;
}
return ;
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&n,&m,&t))
{
getchar();
int tim=,z=;
flag=;
if(n==&&m==&&t==) break;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
sx=i,sy=j;
}
if(map[i][j]=='D')
{
ex=i,ey=j;
}
// if(map[i][j]=='X') z++;
}
getchar();
}
//if(n*m-z<t){printf("NO\n");continue;}
memset(vis,,sizeof(vis));
dfs(sx,sy,);
if(flag) printf("YES\n");
else printf("NO\n");
}
}

Tempter of the Bone(dfs+奇偶剪枝)的更多相关文章

  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. Tempter of the Bone(dfs奇偶剪枝)

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

  3. M - Tempter of the Bone(DFS,奇偶剪枝)

    M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  4. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

  5. hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...

  6. hdu Tempter of the Bone (奇偶剪枝)

    学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.h ...

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

    题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪 ...

  8. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

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

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

  10. hdoj--1010<dfs+奇偶剪枝>

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...

随机推荐

  1. [C入门 - 游戏编程系列] 贪吃蛇篇(六) - 蛇实现

    这一篇是关于设置蛇的属性的,接上一篇(五). 设置蛇的速度,很简单,只要不是负数就行了. void SNK_SetSnakeSpeed(Snake *snake, int speed) { ) sna ...

  2. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  3. UITableView使用总结和性能优化

    UITableView使用总结和性能优化    UITableView有两种风格:UITableViewStylePlain和UITableViewStyleGrouped.如 果我们查看UITabl ...

  4. hdu 1728 逃离迷宫(dFS+优先队列)

    求转弯最少的走路方式!!!! #include<stdio.h> #include<string.h> #include<queue> using namespac ...

  5. Exchange Server 2010升级到Exchange Server 2013概览

  6. scrapy使用crontab定时任务不能自动执行的调试

    在用crontab进行定时任务时,发现任务并没有执行.而手动bash yourshell.sh时可以正常的执行程序.以下是个人的解决流程. 一.将错误打印打out.log */10 * * * * b ...

  7. EffectiveC#17--装箱和拆箱的最小化

    1.如下这段代码会经历装箱和拆箱.例如25会先装箱成object后传递给writeline方法(一次拷贝),在方法内部又 经历拆箱成int(第二次拷贝)后然后调用tostring(). Console ...

  8. JQuery 1.3.2联动获取部门

    Sql       $(document).ready(function(){ $(".dept").bind("click", function () { v ...

  9. Android-现场保护

    现场保护 当一个活动进入到了停止的状态,是有可能被系统回收的,我们都学过Activity的生命周期 当活动处于onPause() ,onStop() ,onDestroy() 三种状态时程序可能会被A ...

  10. UGUI学习之InputField

    密码框在Context type 设置为Passwold 设置背景和调整字体颜色与透明度. 还有一个就是Toggle,(开关)要指定他的Graphic.