Tempter of the Bone 搜索---奇偶性剪枝
Tempter of the Bone
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 1
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.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; int n,m,T,sx,sy,dx,dy;
char a[][];
bool vis[][],Glag;
int map1[][]={ {,},{,},{-,},{,-} }; void dfs(int x,int y,int cur)
{
int i,x1,y1;
if(cur==T && x==dx && y==dy)
{
Glag=true;
return;
}
if(Glag==true) return;
int t,s;
t=T-cur;
s=(int)abs(dx-x)+(int)abs(dy-y);//剩余的时间 t - 剩余的步数 s
//如果,t是奇数,s是奇数。那么t-s是偶数。
//如果,t是偶数,s是奇数。那么t-s是奇数。
//所以只要判断 相减后是否>0 && 偶数。
t=t-s;
if(t<||(t&)==) return;//奇偶性剪枝 for(i=;i<;i++)
{
x1=x+map1[i][];
y1=y+map1[i][];
if(x1>=&&x1<=n && y1>=&&y1<=m && vis[x1][y1]==false && a[x1][y1]!='X')
{
vis[x1][y1]=true;
dfs(x1,y1,cur+);
vis[x1][y1]=false;
}
}
} int main()
{
int i,j,wall;
while(scanf("%d%d%d",&n,&m,&T)>)
{
if(n==&&m==&&T==)break;
for(i=;i<=n;i++)
scanf("%s",a[i]+); wall=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(a[i][j]=='S')
{
sx=i;
sy=j;
}
else if(a[i][j]=='D')
{
dx=i;
dy=j;
}
else if(a[i][j]=='X')
wall++; if(n*m--wall<T)//这也是一个优化,T太大了,根本走不到。
{
printf("NO\n");
continue;
}
Glag=false;
memset(vis,false,sizeof(vis));
vis[sx][sy]=true;
dfs(sx,sy,);
if(Glag==true)
printf("YES\n");
else printf("NO\n");
}
return ;
}
Tempter of the Bone 搜索---奇偶性剪枝的更多相关文章
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- hdu 1010 Tempter of the Bone (奇偶性剪枝)
题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
- 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 ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- 从【BZOJ4173】谈做题技巧
题目描述 ----------------------------------------------------------------------------------------------- ...
- Code Chef February Challenge 2019题解
传送门 \(HMAPPY2\) 咕 话说这题居然卡\(scanf\)的么??? int T;cin>>T; while(T--){ cin>>n>>a>> ...
- 【招聘】滴滴滴~ i春秋内推直通车来咯,帮你找工作!
凑是这么简单粗暴,i春秋冬日特享福利!虽然金九银十已经过去,但素想换工作想找工作的小哥哥小姐姐看过来! [职位方向]渗 透 测 试.代 码 审 计.安全开发.病毒分析.风险控制.安全运维.....任何 ...
- Nginx的反向代理和负载均衡
1 Nginx的反向代理 1.1 什么是反向代理 正向代理 反向代理: 反向代理服务器是引用在服务端.决定哪台服务器提供服务. 1.2 反向代理的模拟 1.2.1 反向代理 应该有一个nginx服务器 ...
- 使用 Hexo + github 搭建个人博客
来自:http://www.cnblogs.com/fengzheng/p/8031518.html Hexo 是什么 Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或 ...
- 阿里云服务器之Tomcat环境搭建以及域名绑定
上一步主要主要讲解在服务器中建立自己的hexo博客环境,最后达到可以远程访问,以及远程git推送到github.这章主要讲解Tomcat环境的搭建,以及域名解析.到这里你的服务器以及可以被全世界的人民 ...
- java简单的运算符和表达式
1.运算符的运算级别分为很多层,第一层是(),括号的运算级别最高. 第二层是+,——,*,/,加,减,乘,除 第三层是==,等于号. 第四层是&&,||,或 与 且 && ...
- 49.RocketMQ 双主搭建(本文非EamonSec原创)
声明:本文非EamonSec原创,copy自网上下载的某个个文件 1.RocketMQ介绍 1.1. 简介 RocketMQ 是一款分布式.队列模型的消息中间件,具有以下特点: 能够保证严格的消息顺序 ...
- jquery插件制作,下拉菜单
要求输入框点击出现下拉菜单,并实现以下功能: 1.首先点击地点标签页,选择好地点: 2.自动显示相应节点标签页显示节点信息,选择好节点 3.自动显示相应的连接点,选择连接点,连接点被选中并被传送的输入 ...
- 【Alpha】Phylab 发布说明
Phylab Alpha阶段发布说明 一.发布地址 Phylab 二.新功能 1. 控制台 由于往届项目控制台并未发布,因此我们在完善后将这部分放在新功能部分.目前使用控制台需要向开发者申请. 1.1 ...