首先,对于一个 '@' 飞上去,飞下来都要耗1点魔力,所以是两点= =

然后站在同一格 魔力可能不同,所以要增加一维。

还有当前搜到的不一定是最小。

别的也没啥。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int N=;
int d[][]={,,-,,,,,-};
struct node{
int x,y,t,mag;
}s,nxt;
char map[N][N];
int vis[N][N][N];
queue <node> q;
int n,m,t,mag,ans;
bool check(node& a)
{
return <=a.x&&a.x<n&&<=a.y&&a.y<m&&map[a.x][a.y]!='#' ;
}
void bfs()
{
while(!q.empty()) q.pop();
memset(vis,,sizeof(vis));
q.push(s);
while(!q.empty())
{
s=q.front();
q.pop();
if(map[s.x][s.y]=='L')
{
ans=min(s.t,ans);
continue;
}
for(int i=;i<;++i)
{
nxt.x=s.x+d[i][];
nxt.y=s.y+d[i][];
if(!check(nxt)) continue;
if(s.mag && !vis[nxt.x][nxt.y][s.mag-])
{
vis[nxt.x][nxt.y][s.mag-]=;
nxt.t=s.t+;
nxt.mag=s.mag-;
q.push(nxt);
}
if(map[s.x][s.y]!='@' && map[nxt.x][nxt.y]!='@' && !vis[nxt.x][nxt.y][s.mag])
{
vis[nxt.x][nxt.y][s.mag]=;
nxt.t=s.t+;
nxt.mag=s.mag;
q.push(nxt);
}
}
}
}
int main()
{
int k=;
while(~scanf("%d%d%d%d",&n,&m,&t,&mag))
{
for(int i=;i<n;i++)
{
scanf("%s",map[i]);
for(int j=;j<m;j++)
{
if(map[i][j]=='Y')
s.x=i,s.y=j;
}
}
s.t=,s.mag=mag;
ans=;
bfs();
printf("Case %d:\n",++k);
if(ans<=t) printf("Yes, Yifenfei will kill Lemon at %d sec.\n",ans);
else puts("Poor Yifenfei, he has to wait another ten thousand years.");
}
}

HDU 2653 - Waiting ten thousand years for Love的更多相关文章

  1. hdu Waiting ten thousand years for Love

    被这道题坑到了,如果单纯的模拟题目所给的步骤,就会出现同一个位置要走两次的情况...所以对于bfs来说会很头痛. 第一个代码是wa掉的代码,经过调试才知道这个wa的有点惨,因为前面的操作有可能会阻止后 ...

  2. HDU 2653 (记忆化BFS搜索+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2653 题目大意:迷宫中有普通点和陷阱.其中普通点可以走可以飞,但是陷阱只能飞.走耗时1,飞耗时2.但 ...

  3. hdu-2619 Love you Ten thousand years

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2619 题目大意: 求出小于n的数的个数,满足ki mod n,1≤i≤n是模n的完全剩余系 解题思路 ...

  4. HDU2653 BFS+优先队列

    Waiting ten thousand years for Love Time Limit: 10000/2000 MS (Java/Others)    Memory Limit: 32768/3 ...

  5. hdu2653之BFS

    Waiting ten thousand years for Love Time Limit: 10000/2000 MS (Java/Others)    Memory Limit: 32768/3 ...

  6. AssetBundle loading failed because.....已解决

    http://blog.csdn.net/ldghd/article/details/9632455 *****************************      一      ******* ...

  7. 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】

    [英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...

  8. sentence patterns

    第四部分     推理题 1.世界上每个角落的每个人都有立场,都有背景,都有推理性,能推理出一个人语言的真意,才成就了真正的推理能力: 2.换言之,如果你能通过一个人的说话推理出其身份职业,你的推理能 ...

  9. C10K问题渣翻译

    The C10K problem [Help save the best Linux news source on the web -- subscribe to Linux Weekly News! ...

随机推荐

  1. Lambda表达式的面纱(一)

    在.NET3.0版本中微软推出了Lambda表达式.这使代码的表述可以更加优雅.但是对于新事物大多会本能的排斥,虽然3.0版本已经推出了好久了,但是我向周围的人了解了一下,用Lambda的人不是很多, ...

  2. Hibernate常见接口说明

    (一)SessionFactory 1. getCurrentSession()和openSession()区别 getCurrentSession创建的session会和绑定到当前线程,而openS ...

  3. OpenCV——肤色检测

    一.RGB color space 检测代码如下: void SkinRGB(IplImage* src,IplImage* dst) { //RGB颜色空间 //均匀照明:R>95,G> ...

  4. (转)Eclipse Shortcuts

    原文地址: http://javapapers.com/core-java/eclipse-shortcuts/ Editors are an integral part of a programme ...

  5. jquery的使用 超级快速入门 熟练使用

    如何使用jquery,首先需要引入jquery的js库文件,可以是免费的cdn资源,也可以是本地下载的资源 使用方法:$(function(){                  这里面写你要执行的代 ...

  6. 【solr专题之四】在Tomcat 中部署Solr4.x

    1.安装Tomcat (1)下载并解压至/opt/tomcat中 # cd /opt/jediael # tar -zxvf apache-tomcat-7.0.54.tar.gz # mv apac ...

  7. python-整理-vs2013新建文件编码

    使用VS2013新建py包和py空文件还有文本文件时发现编码是936.如果代码中写了中文关闭后再打开就乱码了. 找了几个小时,发现模板文件就是936编码,奇怪的是pyclass等其它模板是正常的UTF ...

  8. 【转】nginx之主配置文件:root和alias

    nginx指定文件路径有两种方式root和alias,这两者的用法区别,使用方法总结了下,方便大家在应用过程中,快速响应.root与alias主要区别在于nginx如何解释location后面的uri ...

  9. php 中const和 define的区别

    在php中定义常量时,可用到const与define这两种方法,那他们到底有什么区别呢? 1.const用于类成员变量的定义,一经定义,不可修改.define不可用于类成员变量的定义,可用于全局常量. ...

  10. WPF实现毛玻璃效果

    1和2需要Microsoft.WindowsAPICodePack.Shell.dll 和引用using System.Windows.Interop,并只能在有DwmApi.dll 版本的Windo ...