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 ...
随机推荐
- 搭建ASP JSP运行环境
搭建JSP 服务器 Java + HTML 的运行环境 服务端搭建ASP.NET运行环境
- Spring事务解析4-切面织入
BeanFactoryTransactionAttributeSourceAdvisor作为Advisor的实现类,自然要遵从Advisor的处理方式,当代理被调用时会调用这个类的增强方法,也就是此b ...
- SU Demo之01MakingData--02MultiShot
- express-6 请求和响应对象(1)
URL的组成部分 协议: 协议确定如何传输请求.我们主要是处理http和https.其他常见的协议还有file和ftp. 主机名: 主机名标识服务器.运行在本地计算机(localhost)和本地网络的 ...
- Swift3.0语言教程组合字符串
Swift3.0语言教程组合字符串 Swift3.0语言教程组合字符串,当开发者想要将已经存在的字符串进行组合,形成一个新的字符串,可以使用NSString中的两个方法,分别为appending(_: ...
- BZOJ 2716 [Violet 3]天使玩偶 ——KD-Tree
[题目分析] KD-Tree的例题.同BZOJ2648. [代码] #include <cstdio> #include <cstring> #include <cstd ...
- js与jquery异同
大家都知道jquery是js的一个库,很多东西大多数简写了,让js写起来特别的方便.但是对与学习的人来说,最好是先学会了js再去学jquery会更好.在学得过程中你会发现两者实现的原理是差不多的,但是 ...
- 疯狂java学习笔记之面向对象(五) - 封装、继承、多态
一.封装: 封装的概念: - 合理的隐藏:隐藏不想被外界操作的Field.方法.构造器 - 合理的暴露:一般就是希望给别人调用的方法 e.g:显示器(按键暴露出来操作,但实际的东西/细节方法被隐藏起来 ...
- Java keytool 使用总结
Keytool 是一个Java 数据证书的管理工具 ,Keytool 将密钥(key)和证书(certificates)存在一个称为keystore的文件中. 在keystore里,包含两种数据: ( ...
- Handling events in an MVVM WPF application
Posted: June 30, 2013 | Filed under: MVVM, WPF, XAML |1 Comment In a WPF application that uses the ...