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+剪枝)的更多相关文章

  1. 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 ...

  2. 【HDU - 1010】Tempter of the Bone(dfs+剪枝)

    Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...

  3. HDU1010 --- Tempter of the Bone(dfs+剪枝)

    小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t ...

  4. Tempter of the Bone(DFS+剪枝)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  5. HDU 1010 Tempter of the Bone (DFS+剪枝)

    题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...

  6. HDOJ-1010 Tempter of the Bone(dfs+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 给出一个n*m的迷宫 X为墙 .为空地 S为起点 D为终点 给出时间T 每走一步花费一单位的时间 走过的空 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. Tempter of the Bone(dfs+奇偶剪枝)题解

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. Android Gradle 技巧之二: 最爱命令行

    命令行 很多做 Android 开发不久的同学,习惯于使用图形界面,对命令行操作很陌生甚至恐惧.遇到 AS 运行错误,束手无策.AS 为了确保易用性,也在 UI 界面上屏蔽了很多命令行运行的细节,导致 ...

  2. QT学习之路--创建一个对话框

    Q_OBJECT:这是一个宏,凡是定义信号槽的类都必须声明这个宏. 函数tr()全名是QObject::tr(),被他处理过的字符串可以使用工具提取出来翻译成其他语言,也就是做国际化使用. 对于QT学 ...

  3. hihocoder 1391 [扫描线]

    /* 题意: 两方对阵,互发导弹.防护罩可以让导弹原速反向. 每一枚导弹有发射时间航行时间伤害值. 防护罩也有开启时间和防御时间. 其中一方防护罩开启时间已知,求另一方防护罩合理安排开启时间使得己方受 ...

  4. mac下删除svn账号

    以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al drwxr-xr-x   6 linxyz  staff    204 ...

  5. 21. Clone Graph

    Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its nei ...

  6. linux下重启tomcat,日志查看

    版权声明:本文为楼主原创文章,未经楼主允许不得转载,如要转载请注明来源. 一:关闭tomcat 1.使用cd命令以及常用的tab补全命令进入到tomcat bin所在的目录(可以不用到此目录也行,楼主 ...

  7. 在本地主机上powershell中连接远程主机执行vbs脚本,得到执行结果(2008版及以上)

    在桌面版的主机上远程管理服务器版主机,在本地powershell中连接远程主机执行vbs脚本,得到执行结果. 执行步骤: 1.将本地主机上的Hyper.vbs复制到远程连接主机上.例如,本地vbs脚本 ...

  8. [前端_EasyUI]给easyui的datebox设置默认值,获取不到 的解决方法

    //给eayui datebox设置初始值 $("#ctime").datebox("setValue", function(){ var date = new ...

  9. linux grep命令详解

    linux grep命令详解 简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 ...

  10. nginx_tomcat负载均衡环境

    Nginx+Tomcat搭建 版本 操作系统版本 Centos 6.4 Nginx版本 nginx-1.3.15.tar.gz JDK版本 jdk-7u71-linux-i586 //jdk1.7 T ...