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. python基础-面向对象编程之封装、访问限制机制和property

    面向对象编程之封装 封装 定义:将属性和方法一股脑的封装到对象中,使对象可通过"对象."的方式获取或存储数据. 作用:让对象有了"."的机制,存取数据更加方便 ...

  2. Vmware EXSI服务迁移无法访问故障处理

    Vmware EXSI服务迁移无法访问故障处理 我们在做微服务平台服务时经常在构建IAAS时,因为硬件资源的扩容.缩减等可维护性问题需要迁移或者复制方式扩容方式来快速扩建集群节点,提高微服务运营的可靠 ...

  3. 性能测试——记XX银行保全项目性能问题分析优化

    记XX银行保全项目性能问题分析优化 数据库问题也许是大部分性能问题的关注点,但是JAVA应用与数据库交互的关节,JDBC 就像是我们人体的上半身跟下半身的腰椎,支持上半身,协调下半身运动的重要支撑点. ...

  4. 究极秒杀Loadrunner乱码

    Loadrunner乱码一击必杀 之前有介绍一些简单的针对Loadrunner脚本或者调试输出内容中乱码的一些设置,但是并没能完全解决一些小伙伴的问题,因为那些设置实在能力有限,还是有很多做不到的事情 ...

  5. css 给div添加滚动并隐藏滚动条

    在html中 <div class="box"> <div>下面内容会单独滚动</div> <div class="scroll ...

  6. (四十六)golang--网络编程(简易的聊天系统)

    Go主要的目标之一就是面向大规模后端服务程序,网络通信这块是服务端程序必不可少也是至关键的一部分. 网络编程有两种: (1)TCP Socket编程:是网络编程的主流,之所以叫TCP Socket编程 ...

  7. linux防火墙的相关命令

    一.iptables防火墙(需要安装防火墙sudo apt-get install firewalld命令查看插件)1.基本操作 # 查看防火墙状态 service iptables status # ...

  8. Docker 自建私有Registry 私有仓库

    目录 说明 介绍 原理 搭建 查看配置文件 启动 上传和下载镜像测试 测试上传镜像 测试下载镜像 说明 记录搭建 docker 私有仓库步骤 介绍 docker镜像可以托管到dockerhub中,跟代 ...

  9. php弹出确认框

    下面的代码只需要放在同一个文件中就可以运行了~~ html<a href="__URL__/shanchu/id/{$vo.id}" onclick='return del( ...

  10. 机器学习算法在用户行为检测(UBA)领域的应用

    [摘要]最近看到越来越多的安全圈的同学开始关注UBA或者UEBA的相关产品和技术,恰好这一段时也一直在跟进UBA产品的状况,正如Gartner报告所述,最具创新能力的UBA供应商往往都是一些初创公司, ...