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 ...
随机推荐
- 异步数据库查询 Z
Introduction Microsoft .NET 4.5 introduced new "async and await" methods to provide an eas ...
- for语句
一.for语句的格式格式1:for (控制变量初始化表达式;条件表达式;增量表达式) 语句1; 格式2:for (控制变量初始化表达式;条件表达式;增量表达式){ 语句1; 语句2; -} 注意 ...
- Oracle中的表构造导出到word Sql语句
select * from ( SELECT t1.Table_Name AS "表名称", t3.comments AS "表说明", t1.Column_ ...
- C#全角、半角转换
全角:指一个字符占用两个标准字符位置:半角:指一字符占用一个标准的字符位置. using System; using System.Collections.Generic; using System. ...
- 0601 Spring2.0 发布会及产品发展方向
ProductBacklog:继续向下细化; 1.界面美化,统一界面风格,以简洁美观为主: 2.丰富版面的内容,吸引用户: 3.尝试增加新的版面: Sprint 计划会议:确定此次冲刺要完成的目标 1 ...
- HeartBeat的一些介绍和功能上的一些总结
HeartBeat的作用: 通过HeartBeat,可以将资源(IP以及程序服务等资源)从一台已经故障的计算机快速转移到另一台正常运转的机器上继续提供服务,一般称之为高可用的服务.在实际的生产应用场景 ...
- ubuntu14.04下配置使用openCV3.0
[操 作 系 统] Ubuntu 14.04 LTS [OpenCV版本] 3.0.0-beta [Eclipse 版 本] 3.8.1 需要知识: Linux系统shell命令基础 编译原理 ...
- git免密码pull,push
执行git config --global credential.helper store
- 【转载】OpenGL超级宝典笔记——GLSL语言基础
变量 GLSL的变量命名方式与C语言类似.变量的名称可以使用字母,数字以及下划线,但变量名不能以数字开头,还有变量名不能以gl_作为前缀,这个是GLSL保留的前缀,用于GLSL的内部变量.当然还有一些 ...
- Nginx编译参数大全 configure参数中文详解
./configure --help--help 显示本提示信息--prefix=PATH 设定安装目录--sbin-path=PATH 设定程序文件目录--conf-path=PATH 设定配置文件 ...