hdu Tempter of the Bone
很典型的dfs题,但是涉及到很多的剪枝 。
s | ||||
| | ||||
| | ||||
| | ||||
+ | — | — | — | e |
s | — | — | — | |
— | — | + | ||
| | + | |||
| | ||||
+ | — | — | — | e |
#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"queue"
#include"string.h"
#include"string"
#define mx 105
using namespace std;
char maze[mx][mx];
int n,m,T,sx,sy,ex,ey;
int dir[][]={{,},{-,},{,},{,-}};
bool flag;
bool judge(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m&&maze[x][y]=='.') return true;
return false;
}
void dfs(int x,int y,int t)
{
if(t>T||flag) return;
if(t==T&&x==ex&&y==ey) {flag=true;return;}
int temp=abs(x-ex)+abs(y-ey);//当前位置到目标位置的最短路径
temp=T-t-temp;
if(temp%) return;//奇偶剪枝,不加这个一直tle也是醉了 。
for(int i=;i<;i++)
{
int dx=x+dir[i][];
int dy=y+dir[i][];
if(judge(dx,dy))
{
maze[dx][dy]='X';
dfs(dx,dy,t+);
maze[dx][dy]='.';
}
}
}
int main()
{ int i,j,blocks;
while(cin>>n>>m>>T,n&&m&&T)
{
flag=false;blocks=;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
cin>>maze[i][j];
if(maze[i][j]=='S')
{
sx=i;sy=j;maze[i][j]='X';
}
else if(maze[i][j]=='D')
{
ex=i;ey=j;maze[i][j]='.';
}
else if(maze[i][j]=='X') blocks++;
}
}
if(n*m-blocks->=T)//如果给定的时间数比能走的格子数还要大的话,就肯定不满足条件了
dfs(sx,sy,);
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
hdu Tempter of the Bone的更多相关文章
- HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- hdu Tempter of the Bone (奇偶剪枝)
学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.h ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
- 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 + 奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- loj 1099(最短路)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25956 思路:dist[v][0]代表走到点v的最短路,dist[ ...
- selenium实战-自动退百度云共享群
必备知识 在官网上下好selenium-3.0.1-py2.py3-none-any.whl,然后进入下载文件所在的位置 pip install selenium-3.0.1-py2.py3-none ...
- em与rem
em是相对于父元素的font-size,rem是相对于根元素的font-size. rem的补充: ① 对于不支持它的浏览器,应对方法也很简单,就是多写一个绝对单位的声明.这些浏览器会忽略用rem设定 ...
- BZOJ 2342 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...
- iOS10 UI教程视图的生命周期
iOS10 UI教程视图的生命周期 说到视图的生命周期一般都是指视图控制器的视图生命周期.在视图的声明周期中最主要的有8个方法,分别为loadView().viewDidLoad().viewWill ...
- [自动运维]ant脚本打包,上传文件到指定服务器,并部署
1.根节点使用,表示根目录为当前目录,默认启动的target为build,项目名称为othersysm, <project basedir="." default=" ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
- OpenCV 第一课(安装与配置)
OpenCV 第一课(安装与配置) win10,opencv-2.4.13, 安装, vs2013, 配置 下载安装软件 官网OpenCV下载地址下载最新版本,我下载的是opencv.2.4.13,然 ...
- C#数组的声明方式
C#数组的五种声明方式 一.声明一个未经初始化的数组引用,以后可以把这引用初使化为一个数组实例 int[] intArray; intArray = new int[10]; 注:数组的引用必须以相同 ...
- 推荐两款PC健康小软件
一.前言 对于经常需要坐在电脑前工作一整天的人来说,健康问题是不得不关注的.下面推荐我一直在用的两款体积非常小(几百KB)的健康小软件,也许可以在无形中保护你.提醒你. 1. FadeTop 这是一款 ...