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
 
用深度搜索和奇偶剪枝即可解决
奇偶剪枝-百度百科(里面原理补充部分讲的很好理解):https://baike.baidu.com/item/%E5%A5%87%E5%81%B6%E5%89%AA%E6%9E%9D/10385689
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace::std; int N,M,T,t;
char maps[][];
int maps_[][];
int stx,sty,enx,eny;
int a[][] = {{,},{-,},{,},{,-}};
bool dfs(int n,int m)
{
if( n == enx && m == eny && t == T )
{
return true;
} int ans = T-t-abs(enx-n)-abs(eny-m); //奇偶剪枝,感觉好吊。
if(ans< || ans&)
return false; for(int i = ;i<;i++)
{
int x = n + a[i][];
int y = m + a[i][];
if(maps[x][y] != 'X' && maps_[x][y] != && x>= && y>= && x<N && y<M)
{
t++;
maps_[x][y] = ; if(dfs(x,y))
return true;
else{
t--;
maps_[x][y] = ;
} }
}
return false;
}
int main()
{
while(scanf("%d %d %d",&N,&M,&T) && N != )
{
memset(maps,,sizeof(maps)); //每次输入把地图和标记清空
memset(maps_,,sizeof(maps_));
for(int i=; i<N; i++)
{
scanf("%s",&maps[i]);
for(int j = ; j<M;j++)
{
if(maps[i][j] == 'S') //起始点
{
stx = i;
sty = j;
}
else if(maps[i][j] == 'D') //终点
{
enx = i;
eny = j;
}
}
}
t = ;
maps_[stx][sty] = ; //标记起点
if(dfs(stx,sty))
{
printf("YES\n");
}else
printf("NO\n");
}
return ;
}

hdoj 1010-Tempter of the Bone的更多相关文章

  1. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...

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

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

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

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

  5. hdu 1010 Tempter of the Bone 奇偶剪枝

      如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...

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

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

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

  9. hdu 1010 Tempter of the Bone 深搜+剪枝

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

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

随机推荐

  1. 有关mysql的utf8和utf8mb4,以及Illegal mix of collations for operation 'like'

    参考以下几个帖子: https://www.cnblogs.com/install/p/4417527.html https://blog.csdn.net/Yetmoon/article/detai ...

  2. 安装License需要重启

    "only commands for license handling are allowed in current state" Can you confirm if licen ...

  3. 【填坑】Ubuntu安装vsftpd

    1.安装vsftpdsudo apt-get install vsftpd 安装完毕后或许会自动生成一个帐户"ftp",/home下也会增加一个文件夹.如果没有生成这个用户的话可以 ...

  4. Jupyter Notebook环境安装

    Jupyter Notebook环境安装 一.什么是jupyter Notebook 1.简介 Jupyter Notebook 是基于网页的用于交互计算机的应用程序器可被应用程序. 能让用户将说明文 ...

  5. 微信小程序 wxml 中使用 js函数

    原文链接 1.在 utils 目录下 新建`filter.wxs` var filters = { toFix: function (value) { return value.toFixed(2) ...

  6. Android笔记(四十四) Android中的数据存储——SQLite(六)整合

    实现注册.登录.注销账户 MainActivity.java package cn.lixyz.activity; import android.app.Activity; import androi ...

  7. NFS启动文件系统

    NFS启动文件系统 一.软硬件平台 1.开发板:创龙AM3359核心板,网口采用RMII形式. 2.UBOOT版本:U-Boot-2016.05,采用FDT和DM. 3.交换芯片MARVELL的88E ...

  8. mysql学习之基础篇03

    我们今天来进行建表的基本操作: 首先要建表就要了解列类型,因为建表就是声明列的过程,列声明完成了,表也就建好了. mysql中列分为三大类: 一.数值型 数值型又分为整型和浮点型两种. 先来看整型: ...

  9. [daily] 使用thunderbird通过davmail代理访问Microsoft Exchange Service(OWA)

    前言 我需要接入某企业的邮件服务器, 该服务器没有开通pop3, 没有smtp, 没有imap, 只有exchange. 也就是说必须要使用outlook才能访问. 但是我没有outlook. 方案一 ...

  10. 调试freeradius 3.0 与microsoft AD通过LDAP认证的笔记

    首先来参考文章: a.https://blog.51cto.com/liqingbiao/2146832?utm_source=oschina-app 这个主要参考了基本安装.配置.测试 b.http ...