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. SpringBoot Application深入学习

    本节主要介绍SpringBoot Application类相关源码的深入学习. 主要包括: SpringBoot应用自定义启动配置 SpringBoot应用生命周期,以及在生命周期各个阶段自定义配置. ...

  2. vue项目页面切换到默认显示顶部

    页面切换到默认显示顶部 方法一 使用前端路由,当切换到新路由时,想要页面滚到顶部,或者是保持原先的滚动位置,就像重新加载页面那样. vue-router 能做到,而且更好,它让你可以自定义路由切换时页 ...

  3. centos7 防火墙屏蔽IP

    1.屏蔽指定IP:124.115.0.199 iptables -I INPUT -s 124.115.0.199 -j DROP 2.屏蔽IP段: iptables -I INPUT -s 61.3 ...

  4. 2016 校招, Android 开发,一个本科应届的坎坷求职之路(转)

    转载出处:http://www.nowcoder.com/discuss/3244?type=2&order=0&pos=1&page=1 和大多数的面经不同,我不是大牛,手头 ...

  5. Android的系统框架

    Android的系统架构采用了分层架构的思想,如图1所示.从上层到底层共包括四层,分别是应用程序程序层.应用框架层.系统库和Android运行时和Linux内核.  图1:Android系统架构图 每 ...

  6. 组长组——“多彩夕阳”APP评价

    基于NABCD评论,及改进建议 一.组长组NABCD: N-需求背景: (1)我国老龄化日益加重,已突破两亿.目前人数还在增加,解决老年福祉成为社会关注的民生话题. (2)智能手机越来越普遍,老年人已 ...

  7. sku二维数组里的数组从头到尾叠加组合

    今天工作之余与同事聊天,要是实现一个sku描述里的字段组合的问题.并且实现了请吃饭.哈哈.一顿饭,我和另一位同事积极杠杆的.后来实现了出来. let skuList = [ ['黑色', '白色',' ...

  8. scrapy结合selenium抓取武汉市环保局空气质量日报

    1.前言 目标网站:武汉市环境保护局(http://hbj.wuhan.gov.cn/viewAirDarlyForestWaterInfo.jspx).scrapy对接selenium模块抓取空气质 ...

  9. 【决战西二旗】|理解Sort算法

    前言 前面两篇文章介绍了快速排序的基础知识和优化方向,今天来看一下STL中的sort算法的底层实现和代码技巧. 众所周知STL是借助于模板化来支撑数据结构和算法的通用化,通用化对于C++使用者来说已经 ...

  10. 【项目管理】Mybatis-Generator之最完美配置详解

    今天看到了一篇总结特别详细的关于Mybatis-Generator配置文件的文章,特转载进行记录学习使用. 先附上原文地址链接:张思全----全哥文章 <?xml version="1 ...