hdu 1010 Tempter of the Bone(深搜+奇偶剪枝)
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
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.
'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.
YES
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(深搜+奇偶剪枝)的更多相关文章
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 ...
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- HDU 1010 Tempter of the Bone (DFS+可行性奇偶剪枝)
<题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...
- HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- 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 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- HDU 1010 Tempter of the Bone (广搜+减枝)
题目链接 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. How ...
随机推荐
- [Part 3] 在Ubuntu 16.04源码编译PCL 1.8.1支持VTK和QT
本文首发于个人博客https://kezunlin.me/post/137aa5fc/,欢迎阅读! Part-3: Install and Configure PCL 1.8.1 with vtk q ...
- python容器类型集合的操作
集合(set):集合是一个无序的序列,集合中的元素可以是任意数据类型:表现形式是set(集合的元素),能够实现自动去重:集合传入的必须是一个hashable类型值,(不能存储字典格式的值):并且创建集 ...
- PHP 的 self 关键字用法
之前有人询问 self 关键字的用法,答案是比较明显的:静态成员函数内不能用 this 调用非成员函数,但可以用 self 调用静态成员函数/变量/常量:其他成员函数可以用 self 调用静态成员函数 ...
- 使用node.js开发一个生成逐帧动画小工具
在实际工作中我们已经下下来不下于一万个npm包了,像我们熟悉的 vue-cli,react-native-cli 等,只需要输入简单的命令 vue init webpack project,即可快速帮 ...
- python--debug神器pysnooper
使用它你可以获得什么优势: (1)无需用print就可以获得变量的值: (2)以日志地形式进行保存,方便随时查看: (3)可以根据需要,设置调用函数的深度: (4)多个函数的日志,可以设置前缀进行标识 ...
- vue学习笔记(八)组件校验&通信
前言 在上一章博客的内容中vue学习笔记(七)组件我们初步的认识了组件,并学会了如何定义局部组件和全局组件,上一篇内容仅仅只是对组件一个简单的入门,并没有深入的了解组件当中的其它机制,本篇博客将会带大 ...
- 基于xtrabackup实现mysql备份还原
简介 Xtrabackup2.2版之前包括4个可执行文件: innobackupex: Perl 脚本 xtrabackup: C/C++ 编译的二进制 xbstream: 支持并发写的流文件格式 x ...
- Theano中的导数
计算梯度 现在让我们使用Theano来完成一个稍微复杂的任务:创建一个函数,该函数计算相对于其参数x的某个表达式y的导数.为此,我们将使用宏T.grad.例如,我们可以计算相对于的梯度 import ...
- 如何平滑优雅地在Rancher 2.x中升级cert-manager?
作者: Nassos Michas丨European Dynamics SA, CTO 如果你正在使用由Rancher提供的Helm Chart在Rancher管理的Kubernetes集群中安装ce ...
- Spring Boot整合MyBatis(非注解版)
Spring Boot整合MyBatis(非注解版),开发时采用的时IDEA,JDK1.8 直接上图: 文件夹不存在,创建一个新的路径文件夹 创建完成目录结构如下: 本人第一步习惯先把需要的包结构创建 ...