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. 更改RAC日志组

    alter database add logfile thread 1 group 5 ('+DATA/idb/onlinelog/group5.log') size 256m;alter datab ...

  2. 转:LoadRunner负载测试之Windows常见性能计数器,分析服务器性能瓶颈

    发布于2012-10-8,来源:博客园 监测对象 System(系统) l %Total Processor Time 系统中所有处理器都处于繁忙状态的时间百分比,对于多处理器系统来说,该值可以反映所 ...

  3. ThreadLocal的正确用法

    用法一:在关联数据类中创建private static ThreadLocalThreaLocal的JDK文档中说明:ThreadLocal instances are typically priva ...

  4. Android UI 绘制过程浅析(一)LayoutInflater简介

    前言 这篇blog是我在阅读过csdn大牛郭霖的<带你一步步深入了解View>一系列文章后,亲身实践并做出的小结.作为有志向的前端开发工程师,怎么可以不搞懂View绘制的基本原理——简直就 ...

  5. leetcode 169

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  6. pgadmin中的备份功能消失的原因和找回方法

    pgadmin在正常情况下,在左侧的[对象浏览器]中选中数据库.模式或者表时,右键会出现[备份]和[恢复]的选项(除早期不支持该功能的版本外). 如: 当然,有时候有人会发现,当你想要用这些备份还原功 ...

  7. NRF51822之SPI

    /**@brief Function for initializing a SPI master driver. * * @param[in] p_instance Pointer to SPI ma ...

  8. FireDAC 超时

    FireDAC 超时 Timeout  expired 在Win10 正常. 在Win7 CB的DLL 正常,Delphi的DLL怎么会超时呢??? 果然是连接字符串错了.改为正确的就连接正常了!

  9. Lambda 表达式的基本形式

    基本形式: (input parameters) => expression 其中:运算符“=>”读作“goes to”. 例如: () => 5 * 3; (x) => x ...

  10. Angular JS中 Promise用法

    一.Promise形象讲解A promise不是angular首创的,作为一种编程模式,它出现在1976年,比js还要古老得多.promise全称是 Futures and promises. 而在j ...