Tempter of the Bone

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

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
 
题目大意:
问在某一时间能否到达目的地。走过的地方无法停留或走第二次。
 

1、奇偶剪枝
2、用cin或scanf%s读入
3、千万不要输出No!!!QAQ

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> using namespace std; int n,m,t;
char maze[][];
int xs,ys,xd,yd;
int vis[][];
int a[][]={{,},{-,},{,-},{,}}; bool dfs(int x,int y,int c)
{
if(x==xd&&y==yd&&c==t)
return true;
if(abs(x-xd)+abs(y-yd)>t-c)
return false;
for(int i=;i<;i++)
{
int xx=x+a[i][],yy=y+a[i][];
if(xx>=&&xx<n&&yy>=&&yy<m&&
!vis[xx][yy]&&(maze[xx][yy]=='D'||maze[xx][yy]=='.'))
{
vis[xx][yy]=;//走过的不能再走
if(dfs(xx,yy,c+))
return true;
vis[xx][yy]=;//深搜的回溯
}
}
return false;
} int main()
{
while(scanf("%d%d%d",&n,&m,&t),n||m||t)
{
for(int i=;i<n;i++)
scanf("%s",maze[i]); //奇偶剪枝(奇偶判断)
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(maze[i][j]=='S')
xs=i,ys=j;
if(maze[i][j]=='D')
xd=i,yd=j;
}
int tmp=abs(abs(xs-xd)+abs(ys-yd)-t);
if(tmp%==)
{
printf("NO\n");
continue;
} //搜索
memset(vis,,sizeof(vis));
vis[xs][ys]=;
if(dfs(xs,ys,))
printf("YES\n");
else
printf("NO\n");
}
return ;
}

hdu 1010 Tempter of the Bone(深搜+奇偶剪枝)的更多相关文章

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

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

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

  3. HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)

    需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...

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

    <题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...

  5. HDU 1010 Temper of the bone(深搜+剪枝)

    Tempter of the Bone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

  6. HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  7. HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝

    传送门: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1010 ZOJ:http://acm.zju.edu.cn/onlinejudge/showPr ...

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

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

  9. HDU 1010 Tempter of the Bone (广搜+减枝)

    题目链接 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. How ...

随机推荐

  1. J.U.C剖析与解读1(Lock的实现)

    J.U.C剖析与解读1(Lock的实现) 前言 为了节省各位的时间,我简单介绍一下这篇文章.这篇文章主要分为三块:Lock的实现,AQS的由来(通过演变的方式),JUC三大工具类的使用与原理剖析. L ...

  2. 启动elasticsearch

       - name: source env      shell: source /etc/profile    - name: make elastic permission      shell: ...

  3. PostGIS 爆管分析之找出上游阀门

    环境: Win10 ArcMap10.4(用于数据处理) postgresql9.4 postgis2.2.3 pgRouting2.3(postgresql插件) 说明: 继上一篇文章做了爆管分析找 ...

  4. ArcGIS 问题汇总

    1.Arcgis10.4出现Manager打不开的情况 解决方法: 1.检查进程中是否有占用4000以及6080端口的进程,如果有关闭 2.检查进程中是否有javaw.exe这个进程,如果有就把他结束 ...

  5. PHP安全之道学习笔记2:编码安全指南

    编码安全指南 编程本身就应该是一门艺术,而安全编程更是一种在刀尖上舞蹈的艺术,不仅要小心脚下的锋利寒刃,更要小心来自网络黑客或攻击者的狂轰乱炸. - by code artist 1.hash比较的缺 ...

  6. pdf 在线预览之 pdfjs插件

    这个插件不需要阅读器 也不会屏蔽签章 但是也是兼容到ie11

  7. day 12 函数名的应用 闭包 迭代器

    今日主要内容 1, 函数名的应用,第一类对象 函数名可以像变量一样进行使用   #再函数名后面添加() 才是对函数的调用, 否则打印的是函数的内存地址 1.赋值 2.作为list元素 3.作为参数 d ...

  8. IEnumerable和IEnumerator详解

    引言 IEnumerable是可枚举的所有非泛型集合的基接口, IEnumerable包含一个方法GetEnumerator(),该方法返回一个IEnumerator:IEnumerator提供通过C ...

  9. PHP页面跳转三种实现方法

    一.header()函数 header()函数是PHP中进行页面跳转的一种十分简单的方法.header()函数的主要功能是将HTTP协议标头(header)输出到浏览器.header()函数的定义如下 ...

  10. 记录我的 python 学习历程-Day03 数据类型 str切片 for循环

    一.啥是数据类型 ​ 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能呀,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,"汉"是文字,否则它是分 ...