【奇偶剪枝】【HDU1010】Tempter of the Bone
题意:输入一个n*m的迷宫,和一个T:可以在迷宫中生存的最大时间。S为起点,D为终点。并且,每个格子只能踩一次,且只能维持一秒,然后该块地板就会塌陷。所以你必须每秒走一步,且到D点时,所用时间为T。
TIPS:可以在中途某个点就能通过x+y的奇偶性与剩余时间的奇偶性判定 能否到D ,达到剪枝的目的。
代码如下
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdlib.h>
using namespace std;
char map[9][9];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int n,m,t,sum;
int sx,sy,ddx,ddy;
bool dfs(int x,int y,int time)
{
int px,py;
if(x==ddx && y==ddy && time==t)
{
return true;
}
else
{
if(abs(ddx-x)+abs(ddy-y)>t-time)return false;
for(int i=0;i<4;i++)
{
px=x+dx[i];
py=y+dy[i];
if(map[px][py]!='X' && time+1<=t)
{
map[px][py]='X';
if(dfs(px,py,time+1))return true;
map[px][py]='.';
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&t),n || m || t)
{
memset(map,'X',sizeof(map));
sum=0;
getchar();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
sx=i;
sy=j;
}
if(map[i][j]=='D')
{
ddx=i;
ddy=j;
}
if(map[i][j]=='.')sum++;
}
getchar();
}
if(sum+1<t || (t+sx+sy+ddx+ddy)%2==1)printf("NO\n");
else
{
map[sx][sy]='X';
if(dfs(sx,sy,0))printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
【奇偶剪枝】【HDU1010】Tempter of the Bone的更多相关文章
- HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- 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 ...
- 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 ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU1010 Tempter of the Bone(回溯 + 剪枝)
本文链接:http://i.cnblogs.com/EditPosts.aspx?postid=5398734 题意: 输入一个 N * M的迷宫,这个迷宫里'S'代表小狗的位置,'X'代表陷阱,‘D ...
- HDU1010 --- Tempter of the Bone(dfs+剪枝)
小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t ...
- HDU1010 Tempter of the Bone
解题思路:相当经典的一题,回溯,具体细节处理见代码. #include<cstdio> #include<cstring> #include<algorithm> ...
- 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 ...
随机推荐
- serialVersionUID作用
serialVersionUID适用于Java的序列化机制.简单来说,Java的序列化机制是通过判断类的serialVersionUID来验证版本一致性的.在进行反序列化时,JVM会把传来的字节流中的 ...
- VF(动态规划)
VF 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make a ...
- hdu 3061 (最大权闭合图)
分析:城池之间有依赖关系,汇点与能获得兵力的城池连接,容量为可以获得的兵力,损耗兵力的城池与汇点连接容量为损耗的兵力,有依赖关系的城池间连边,容量为无穷大,跑网络流求出的最小割就是损耗的最小兵力,,, ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
- 【指数型母函数+非递归快速幂】【HDU2065】"红色病毒"问题
大一上学完数分上后终于可以搞懂指数型母函数了.. 需要一点关于泰勒级数的高数知识 题目在此: "红色病毒"问题 Time Limit: 1000/1000 MS (Java/Oth ...
- ECSHOP用户评论
可以不需要审核吗?现在的用户评论要审核才能显示 ,我需要不用审核就可以显示可以么? 在论坛上看见这个问题,顺便就记录下来吧. 这个是可以的,下面是操作步骤 后台->系统设置->商店设置-& ...
- java学习之i/o
基本的输入输出 这里有两种方法,其中一种被注释了,可以换着注释后测试一遍 class TestSystem { public static void main(String[] args) { /* ...
- iOS中json解析出现的null,nil,NSNumber的问题
在iOS开发过程中经常需要与服务器进行数据通讯,Json就是一种常用的高效简洁的数据格式. 问题现象 但是几个项目下来一直遇到一个坑爹的问题,程序在获取某些数据之后莫名崩溃.其实很早就发现了原因:由于 ...
- MyEclipse开发的java web项目在 Eclipse中无法识别
不能识别项目解决办法 在eclipse下,右键项目properties -> project fac e ts 选中 Dynamic web module 选择后面的版本为 2.5(运行环 ...
- java教程
http://www.xfonlineclass.com/ http://java.itcast.cn/ http://www.xasxt.com/index.php/list/161 [UI]htt ...