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 ...
随机推荐
- 记一次MBR锁机病毒分析
有一天,在机缘巧合之下我获得了一个锁机软件(是多巧合阿喂!),然后兴高采烈的把它拖入了虚拟机里蹂躏(>_<!). 很巧,软件有虚拟机检测... Emmmm好吧,随便过一下... 我用的虚拟 ...
- Getting Started with Elastic Search in .NET
I have been working on many application during my career. Many if not all had some searching capabi ...
- 基本项目框架搭建 sqlserver druid配置
1. 我的连接池采用的是阿里云的druid的连接池,工具是IDEA 框架是springboot+maven 以下是我的项目框架结构 2. pom 中配置 <?xml version=&quo ...
- springBoot整合MyBatise及简单应用
springBoot整合MyBatise及简单应用 我采用的是 工具IDEA 框架是springBoot+maven+Mybatise 第一步: pom.xml 引入相关jar包 <?xml v ...
- 从源码的角度再学「Thread」
前言 Java中的线程是使用Thread类实现的,Thread在初学Java的时候就学过了,也在实践中用过,不过一直没从源码的角度去看过它的实现,今天从源码的角度出发,再次学习Java Thread, ...
- mac编辑器vim美化
mac编辑器vim美化 contents 环境 效果呈现 安装 quick start 环境 mac10.13.6,vim7(该版本mac自带的vim是7),git mac下vim的配置文件有两处 一 ...
- java 实现七大基本排序算法
一. 选择排序 /** * 选择排序: int arr[] = { 5, 6, 2, 7, 8, 6, 4 }; * * 第0趟 5 2 6 7 6 4 8 第1趟 2 5 6 6 4 7 8 第2趟 ...
- Protobuf底层存储原理
参考官网, 序列化原理 底层二进制存储 message Test1 { optional int32 a = 1; } 并设置为a=150,序列化到一个文件中,查看文件,得到下面的二进制: 08 96 ...
- /proc/xxx/maps简要记录
定位内存泄漏基本上是从宏观到微观,进而定位到代码位置. 从/proc/meminfo可以看到整个系统内存消耗情况,使用top可以看到每个进程的VIRT(虚拟内存)和RES(实际占用内存),基本上就可以 ...
- [HNOI2019]多边形
Luogu5288 注意:n边形里共有n-3条边 最优步数=不与n相连的边数,关键是方案数. 按照处理顺序可以转化为树形结构即二叉树森林,转移方案数用组合数即可 关键是快速处理修改. 1.最优解减少一 ...