Tempter of the Bone---hdu1010(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010
折磨我一下午
题目大意: 从s点走到d点能否恰好走k步 刚开始以为是广搜,其实是深搜。
dfs多优化一下才会过。
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<ctype.h>
using namespace std;
#define N 10
#define memset(a,b) memset(a,b,sizeof(a))
#define Lson r<<1|1
#define Rson r<<1
struct node
{
int x,y,step;
}s,e;
int n,m,k;
int dis[][]={{,},{-,},{,},{,-}};
int vis[N][N];
char maps[N][N];
int is=; void dfs(node t)
{
if(is)
return;
if(t.x==e.x && t.y==e.y && t.step==k)
{
is=true;
return;
}
if(t.step>=k)
return; int Min=(int)(abs(t.x-e.x)+abs(t.y-e.y));
if(Min>k-t.step)
return;
if(Min%!=(k-t.step)%)
return;
if(t.x==e.x && t.y==e.y)
return; node q;
for(int i=;i<;i++)
{
q.x=t.x+dis[i][];
q.y=t.y+dis[i][];
q.step=t.step+;
if(is || q.x< || q.x>=n || q.y< || q.y>=m || maps[q.x][q.y]=='X')
continue;
if(q.x==e.x && q.y==e.y && q.step==k)
{
is=true;
return;
}
char ch=maps[q.x][q.y];
maps[q.x][q.y]='X';
dfs(q);
maps[q.x][q.y]=ch;
}
} int main()
{
while(scanf("%d %d %d",&n,&m,&k),n+m+k)
{
memset(maps,);
int ans=;
for(int i=;i<n;i++)
{
scanf("%s",maps[i]);
for(int j=;j<m;j++)
{
if(maps[i][j]=='S')
{
s.x=i;
s.y=j;
s.step=;
}
else if(maps[i][j]=='D')
{
e.x=i;
e.y=j;
}
else
ans++;
} }
if(k->ans)
{
printf("NO\n");
continue;
}
maps[s.x][s.y]='X';
is=;
dfs(s);
if(is==true)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
Tempter of the Bone---hdu1010(dfs+剪枝)的更多相关文章
- 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 ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
- HDU1010 --- Tempter of the Bone(dfs+剪枝)
小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t ...
- Tempter of the Bone(DFS+剪枝)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- HDU 1010 Tempter of the Bone (DFS+剪枝)
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...
- HDOJ-1010 Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 给出一个n*m的迷宫 X为墙 .为空地 S为起点 D为终点 给出时间T 每走一步花费一单位的时间 走过的空 ...
- 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 ...
- hdoj 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 ...
- Tempter of the Bone(dfs+奇偶剪枝)题解
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- [ActionScript 3.0] 喷泉效果
pall为水珠影片剪辑 var count:int = 500; var zl:Number = 0.5; var balls:Array; balls = new Array(); for (var ...
- 因开启SELinux导致httpd报403
各项权限都检查过了,SELinux允许的端口也找过了.同目录下的其他文件夹是正常的,这个文件夹就抱403. 临时关闭selinux后正常.估计是没有配置运行上下文. chcon -R -t httpd ...
- python socket 常见方法及 简单服务/客户端
socket 常见方法: 补充说明:what is file descriptor? 文件描述符是什么? 参考(http://stackoverflow.com/questions/8191905/w ...
- 转:Tomcat安装配置及站点说明
原文地址:http://www.cnblogs.com/Johness/archive/2012/07/20/2600937.html 1.首先是Tomcat的获取和安装. 获取当然得上Apache的 ...
- VBA_Excel_教程:分枝循环结构
Sub 分枝() tmp = Cells(, ).Value '变量不用定义,当前写代码的Sheet Debug.Print tmp " Then Debug.Print "A&q ...
- Python从题目中学习:random() module
最近在给公司培训Python,布置了一道题: ----------------------------------------------------------------------------- ...
- lintcode-【简单题】链表求和
题目: 你有两个用链表代表的整数,其中每个节点包含一个数字.数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头.写出一个函数将两个整数相加,用链表形式返回和. 样例: 给出两个链表 3- ...
- java学习第10天 (增加关于eclipse添项目)
自己遇到一个问题..觉得有必要说下,就是如何将别人发给你的文件也就是项目如何导入到你的eclipse中,不是直接add那么简单,首先右键找到import,找到general,展开找到existing ...
- java并发编程_CountDownLanch(倒计数锁存器)应用场景
使用介绍: 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDown() 方法,所以在 ...
- 解决阿里云数据库RDS报错The table '/home/mysql/data3015/tmp/#sql_13975_23' is full
查询任何一条语句都显示 The table '/home/mysql/data3015/tmp/#sql_13975_23' is full 查看了下数据库利用磁盘空间没有满, 阿里云的处理方式: 1 ...