M - Tempter of the Bone

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
 
 
 
 //走迷宫,第一行是 n ,m (都小于7) 然后是一个时间 t ,然后是地图,S 是起点,D 是终点,走一步一秒,且不能回头,问是否能在 t 时刻恰好到终点
奇偶剪枝,
想一下就知道,怎么走到终点的步数奇偶性都不会改变
abs(s_x-e_x)+abs(s_y-e_y) 这个是起点到终点无视障碍的最短步数,如果奇偶不同,不需要 dfs 。直接 NO。
补充一下,奇-奇=偶 , 偶-偶=偶 
 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; char map[][];
bool vis[][];
int s_x,s_y,e_x,e_y;
int a,b,t,ok; bool check(int x,int y)
{
if (x<=||x>a||y<=||y>b)
return ;
if (map[x][y]=='X'||vis[x][y]||ok)
return ;
return ;
} void dfs(int x,int y,int time)
{
vis[x][y]=;
//printf("(%d,%d)\n",x,y);
if (x==e_x&&y==e_y&&time==t)//满足条件到终点
{
ok=;
return;
} int temp=t-time-(abs(x-e_x)+abs(y-e_y)); if (temp<)//剩余步数小于 0
return; int n_x,n_y; n_x=x,n_y=y+;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x+,n_y=y;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x,n_y=y-;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
} n_x=x-,n_y=y;
if (check(n_x,n_y))
{
dfs(n_x,n_y,time+);
vis[n_x][n_y]=;
}
} int main()
{
int i,j;
while (scanf("%d%d%d",&a,&b,&t)&&a+b+t)
{
getchar();
int wall=;
for (i=;i<=a;i++)
{
for (j=;j<=b;j++)
{
scanf("%c",&map[i][j]);
if (map[i][j]=='S')
{
s_x=i;
s_y=j;
}
if (map[i][j]=='D')
{
e_x=i;
e_y=j;
}
if (map[i][j]=='X')
wall++;
}
getchar();
} if (a*b-wall<=t)//所有路都走了还到不了终点,注意是 <=t ,可以少300ms
{
printf("NO\n");
continue;
} ok=;
memset(vis,,sizeof(vis));
int temp=t-(abs(s_x-e_x)+abs(s_y-e_y)); if (temp%==)//奇偶性相同才bfs
dfs(s_x,s_y,); if (ok)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

M - 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. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Linux学习笔记 (四)归档和压缩

    一.zip压缩命令: 1.压缩文件: 格式:zip 压缩文件 源文件 例:zip abc.zip abc  //将abc文件压缩到abc.zip文件内. 2.压缩目录: 格式:zip –r 压缩目录 ...

  2. 基于ShaderX5的顶点动画

    关于顶点动画,ShaderX5里有篇专门来讲,在虚幻3引擎里也有一个更加丰富的实现.使用了一个Pivot Painter的3dmax脚本.其实自己灵活用vertex color可以避开使用Pivot ...

  3. Android代码实现控件闪烁效果

    代码地址如下:http://www.demodashi.com/demo/13162.html 前言 在项目开发过程中,我们有时会遇到需要控件闪烁和停止的问题,这个用xml是可以实现的,但是为了在使用 ...

  4. python学习笔记之pdb调试

    之前一直说要学python可还是一直停留在看的层面,昨天大神手把书教我pdb调试,说要摆脱IDE集成开发环境编程,感激不尽,立一个flag,python一定要入门! 1.进入方式 1)windows ...

  5. Jenkins spring boot 自动部署方案

    原文地址:http://www.cnblogs.com/skyblog/p/5632869.html 现在主流的自动部署方案大都是基于Docker的了,但传统的自动部署方案比较适合中小型公司,下面的方 ...

  6. /u200B 8203 Zero-width space 问题

    [TestMethod] public void TestBom() { string str = "123​";//这个字符串是错误的有问题 长度4 ).Select(x =&g ...

  7. TensorFlow学习笔记 速记2 报错:failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICE

    版本: tensorflow-gpu 原因: 在创建session时没有使用我想让它用的gpu 解决方案: 1. 在python程序中: import os os.environ["CUDA ...

  8. mysql创建数据库时设置编码方式

    CREATE DATABASE procedure_function DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  9. 手动grub引导redhat

    grub是redhat默认的引导程序,在安装redhat时会提示是否安装bootloader,但自己手贱选择不安装,待系统重启时就是grub命令行界面,不能直接进系统.瞬时感觉麻烦大了,只能手动输入咯 ...

  10. javacript计时

    简单的计时: var t=setTimeout("alert('5 秒!')",5000) 无限计时: var c=0 var t function timedCount() { ...