首先,对于一个 '@' 飞上去,飞下来都要耗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. oracle行号排序问题

    1.创建一个student,并且插入数据 ),age int) '); '); '); '); '); commit; 2.直接按照age进行排序显示行号: select * from(select ...

  2. UISwitch 监听响应

    UISwitch *swh = [[UISwitch alloc]initWithFrame:CGRectMake(100,100, 50, 30)];        swh.on = YES;    ...

  3. UVA 11426 GCD - Extreme (II) (欧拉函数)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Problem JGCD Extreme (II)Input: Standard ...

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

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

  5. 关于 jQuery中 function( window, undefined ) 写法的原因

    今天在读 jQuery 源码的时候,发现下面的写法: (function(window,undefined){ ...// code goes here })(window); window 作为参数 ...

  6. [Zookeeper研究]一 Zookeeper技术简介

    最近的项目中使用到了Zookeeper.Kafka以及Storm.仔细研究了一下,觉得这几个开源项目对于搞分布式的人来说是非常有用的,所以想把自己的一点心得体会总结一下,希望能对大家有所帮助. 首先从 ...

  7. 掌握string.h里的常用函数

    字符串输出函数 puts 格式:  puts(字符数组名) 功能:把字符数组中的字符串输出到显示器. 即在屏幕上显示该字符串. 字符串输入函数 gets 格式:  gets (字符数组名) 功能:从标 ...

  8. javascript string对象的属性与方法

    一 创建string对象 new string('string'); 更直接的定义方法是var str = 'string'; 二 string属性 1.constructor 2.lenght 字符 ...

  9. 安卓手机用-----Exchange Activesync---同步Gmail日历联系人

    微软Exchange Activesync是一个跨平台的移动设备同步协议 支持很多手机操作系统,比如诺基亚的塞班.黑莓的palm.WindowsMobile.Iphone.安卓等.这些手机上都可以用这 ...

  10. ArcGIS 栅格数据已加载后的获取

    原文 http://www.cnblogs.com/zoe-j/archive/2012/02/16/2354037.html 简单记一下,最近开始做Arcgis engine的开发, 已经通过了to ...