ZOJ2110 HDU1010 搜索 Tempter of the Bone
大意是给一个矩阵,叫你是否可以在给定的可走路径上不重复地走,在最后一秒走到终点。
我用了两个剪枝,且称其为简直001和剪枝002,事实证明001不要都可以,002不要也能过--||。就当练习一下剪枝。
特别是002很有用:
if( d % 2 != (Time-t) % 2 )
return false ; (d=~x+~y)
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
using namespace std;
const int INF=10000000;
int dis[8][8];
char c[8][8];
int x[]={0,-1,0,1};
int y[]={1,0,-1,0};
int sx,sy;
int n,m,t;
int fx,fy;
void _Searchdis(int xx,int yy)
{
for(int i=0;i<4;i++)
if(xx+x[i]>=1&&xx+x[i]<=n&&yy+y[i]>=1&&yy+y[i]<=m)
if(c[xx+x[i]][yy+y[i]]!='X')
if(dis[xx][yy]+1<dis[xx+x[i]][yy+y[i]]){
dis[xx+x[i]][yy+y[i]]=dis[xx][yy]+1;
_Searchdis(xx+x[i],yy+y[i]);
}
return ;
}
bool _BFS(int xx,int yy,int steps)
{
if(xx==sx&&yy==sy&&steps==t) return true;
if(steps+dis[xx][yy]>t) return false;//剪枝1
if((abs(xx-sx)+abs(yy-sy))%2!=abs(t-steps)%2) return false;//剪枝2
for(int i=0;i<4;i++)
if(xx+x[i]>=1&&xx+x[i]<=n&&yy+y[i]>=1&&yy+y[i]<=m)
if(c[xx+x[i]][yy+y[i]]!='X')
{
c[xx+x[i]][yy+y[i]]='X';
if(_BFS(xx+x[i],yy+y[i],steps+1)) return true;
c[xx+x[i]][yy+y[i]]='.';
}
return false;
}
int main()
{
int i,j;
while(scanf("%d%d%d",&n,&m,&t)&&(n||m||t))
{
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
{
cin>>c[i][j];
if(c[i][j]=='D'){ sx=i;sy=j;}
if(c[i][j]=='S'){ fx=i;fy=j;}
dis[i][j]=INF;
}
}
dis[sx][sy]=0;
_Searchdis(sx,sy);
c[fx][fy]='X';//不要搞忘
if(_BFS(fx,fy,0)) printf("YES\n");
else printf("NO\n");
}
return 0;
}
ZOJ2110 HDU1010 搜索 Tempter of the Bone的更多相关文章
- 【奇偶剪枝】【HDU1010】Tempter of the Bone
题意:输入一个n*m的迷宫,和一个T:可以在迷宫中生存的最大时间.S为起点,D为终点.并且,每个格子只能踩一次,且只能维持一秒,然后该块地板就会塌陷.所以你必须每秒走一步,且到D点时,所用时间为T. ...
- 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(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奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- Tempter of the Bone 搜索---奇偶性剪枝
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
随机推荐
- zookeeper简单介绍
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt193 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系 ...
- Linq 实现sql中的not in和in条件查询
T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products Where CategoryID in (1, 2) T-S ...
- [ASP.NET MVC]笔记(三) 成员资格、授权和安全性
阻止CSRF(跨站请求伪造) ASP.NET MVC提供了一个阻止CSRF攻击的好方法 在每个提交的表单中包含 @using (Html.BeginForm("Index", &q ...
- Nand Flash驱动(实现初始化以及读操作)
简单制作一个Nand Flash驱动(只需要初始化Flash以及读Flash) 打开2440芯片手册,K9F2G08U0M芯片手册(因为2440中Nand Flash是用的256MB(2Gb)内存,8 ...
- Mybatis源码解析-BoundSql
mybatis作为持久层,其操作数据库离不开sql语句.而BoundSql则是其保存Sql语句的对象 前提 针对mybatis的配置文件的节点解析,比如where/if/trim的节点解析可见文章Sp ...
- 201521123002 《Java程序设计》第3周学习总结
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 2. 书面作 ...
- 201521123101 《Java程序设计》第2周学习总结
1. 本周学习总结 使用码云保存管理自己的代码: 学习String和Array: 继续对JAVA的探索,希望以后能在编程上更顺畅一些 2. 书面作业 1.使用Eclipse关联jdk源代码(截图),并 ...
- 201521123012 《Java程序设计》第九周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 1.本次PTA作业题集异常 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...
- Project Euler:99 Largest exponential C++
Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator woul ...
- Python学习笔记005_文件_OS_模块_pickle
>>> >>> # 文件 open()方法是打开文件,它有很多参数,第一个文件名是必须的(带路径)>>> >>> f = ope ...