首先,对于一个 '@' 飞上去,飞下来都要耗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. Spring MVC中数据绑定(转)

    Spring MVC中数据绑定 比如Product有一个createTime属性,是java.util.Date类型.那么最简单的转型处理是,在SimpleFormController中覆盖initB ...

  2. Emacs颜色设置

    1.下载color-theme主题包 下载链接:http://download.savannah.gnu.org/releases/color-theme/ color-theme-6.6.0.zip ...

  3. JDK,TomCat安装配置

    JDK.Tomcat.myEclipse安装配置 准备安装包 JAVA运行环境包 JDK1.7下载地址: http://www.veryhuo.com/down/html/43205.html Jsp ...

  4. ImageView一例

    参考自<疯狂android讲义>2.4节 效果如下: 当点击图上某点时,将之附近放大至下图. 布局文件: <LinearLayout xmlns:android="http ...

  5. HTML5学习笔记一:新增主体结构元素

    Dreamweaver快捷键: 属性面板:Ctrl+F3 新建文档:Ctrl+N 选择用网页查看:F12 新增的主体结构元素: section元素(例子如下): <!DOCTYPE HTML&g ...

  6. slime+sbcl for common lisp

    sudo apt-get install slime audo apt-get install sbcl ;;sbcl+slime for common lisp ;;sudo apt-get ins ...

  7. LeetCode_Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. class Solutio ...

  8. Mybatis的连接池

    先总结一个原则:mytatis的连接池最大值poolMaximumActiveConnections尽量跟服务器的并发访问量持平以至于大于并发访问量. 原因:在org.apache.ibatis.da ...

  9. Apache、php、mysql单独安装配置

    php, 安装版的,http://www.php.net/manual/zh/install.php.也有不安装版直接配置的. 在Windows 7下如何进行PHP配置环境. PHP环境在Window ...

  10. scheme 模拟queue

    [code 1] shows a implementation of queue. The function enqueue! returns a queue in that the obj is a ...