Waiting ten thousand years for Love

Time Limit: 10000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 615    Accepted Submission(s): 205

Problem Description
It was ten thousand years, after Demon Lemon caught Yifenfei’s love. In order to revenge and save his love, Yifenfei have been practising sword all day long and his Kongfu skills becomes so powerful that he can kill Demon Lemon immediately. Recently, Yifenfei have found Lemon’s castle, and now he is going to kill Lemon. At the same time, hearing about the terrible news, Demon Lemon is now preparing for escaping...

Now Yifenfei has got the map of the castle.

Here are all symbols of the map:

Only one ‘Y’ Indicates the start position of Yifenfei.

Only one ‘L’ Indicates the position of Demon Lemon.

‘.’ Indicate the road that Yifenfei can walk on it, or fly over it.

‘#’ Indicate the wall that Yifenfei can not walk or flay through it.

‘@’ Indicate the trap that Yifenfei can not walk on it, but can fly over it.

Yifenfei can walk or fly to one of up, down, left or right four directions each step, walk costs him 2 seconds per step, fly costs him 1 second per step and 1 magic power. His magic power will not increased, and if his magic power is zero, he can not fly any more.

Now Yifenfei asks you for helping him kill Demon Lemon smoothly. At the same time, Demon Lemon will Leave the castle Atfer T seconds. If Yifenfei can’t kill Demon Lemon this time, he have to wait another ten thousand years.

 
Input
Lots of test cases, please process to end of file. In each test case, firstly will have four integers N, M, T, P(1 <= N, M, P <= 80, 1 <= T <= 100000), indicates the size of map N * M, the Lemon’s leaving time(after T seconds, Lemon will disappeared) and Yifenfei’s magic power. Then an N * M two-dimensional array follows indicates the map.
 
Output
For each test case, first Print a line “Case C:”, C indicates the case number. Then, if Yifenfei can kill Demon Lemon successfully, Print “Yes, Yifenfei will kill Lemon at T sec.”, T indicates the minimum seconds he must cost. Otherwise, Print ”Poor Yifenfei, he has to wait another ten thousand years.”
 
Sample Input
2 3 2 2
Y@L
###
2 3 4 1
Y@L
###
2 3 4 0
Y.L
###
2 3 3 0
Y.L
###
 
Sample Output
Case 1:
Yes, Yifenfei will kill Lemon at 2 sec.
Case 2:
Poor Yifenfei, he has to wait another ten thousand years.
Case 3:
Yes, Yifenfei will kill Lemon at 4 sec.
Case 4:
Poor Yifenfei, he has to wait another ten thousand years.

Hint

Hint
Case 1: Yifenfei cost 1 second and 1 magic-power fly to ‘@’,
but he can not step on it, he must cost another 1 second
and 1 magic-power fly to ‘L’ and kill Lemon immediately.
Case 2: When Yifenfei Fly to ‘@’, he has no power to fly,
and is killed by trap.

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=80+10;
char Map[MAX][MAX];
int mark[MAX][MAX][MAX];//在位置i,j剩余魔力k是否标记
int n,m,t,p;
int dir[4][2]={0,1,0,-1,1,0,-1,0}; struct Node{
int x,y,time,m;
Node(){}
Node(int X,int Y,int Time,int M):x(X),y(Y),time(Time),m(M){}
bool operator<(const Node &a)const{
return time>a.time;
}
}start; priority_queue<Node>q;
int BFS(int &flag){
while(!q.empty())q.pop();
Node next,oq;
q.push(start);
mark[start.x][start.y][start.m]=flag;
while(!q.empty()){
oq=q.top();
q.pop();
if(Map[oq.x][oq.y] == 'L')return oq.time;
if(oq.time>t)return INF;
for(int i=0;i<4;++i){
next=Node(oq.x+dir[i][0],oq.y+dir[i][1],oq.time+1,oq.m);
if(next.x<0 || next.y<0 || next.x>=n || next.y>=m)continue;
if(Map[next.x][next.y] == '#')continue;
if(Map[next.x][next.y] != '@' && Map[oq.x][oq.y] != '@' && mark[next.x][next.y][next.m] != flag){
++next.time;
q.push(next);
mark[next.x][next.y][next.m]=flag;
}
if(next.m>0 && mark[next.x][next.y][next.m-1] != flag){
--next.m;
next.time=oq.time+1;
q.push(next);
mark[next.x][next.y][next.m]=flag;
}
}
}
return INF;
} int main(){
int num=0;
while(cin>>n>>m>>t>>p){
for(int i=0;i<n;++i)cin>>Map[i];
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
if(Map[i][j] == 'Y')start.x=i,start.y=j;
}
}
start.time=0,start.m=p;
int temp=BFS(++num);
cout<<"Case "<<num<<":\n";
if(temp>t)cout<<"Poor Yifenfei, he has to wait another ten thousand years."<<endl;
else cout<<"Yes, Yifenfei will kill Lemon at "<<temp<<" sec."<<endl;
}
return 0;
}

hdu2653之BFS的更多相关文章

  1. HDU2653 BFS+优先队列

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

  2. 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)

    图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...

  3. 【BZOJ-1656】The Grove 树木 BFS + 射线法

    1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 186  Solved: 118[Su ...

  4. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  5. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  6. Sicily 1215: 脱离地牢(BFS)

    这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...

  7. Sicily 1048: Inverso(BFS)

    题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...

  8. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  9. Sicily 1051: 魔板(BFS+排重)

    相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒.关于康托展开可以 ...

随机推荐

  1. 多路径路由算法选择(1)——ECMP、WCMP

    不要问为什么,现在的工作转向了网络路由协议的设计. 传统的网络拓朴结构可以形象的表示为树结构,我们称之为“有中心的网络拓扑结构”,简单地认为很多流量请求最终会汇聚到主干网这样的路由中心,才能转发到下一 ...

  2. Ceph的工作原理及流程

    本文将对Ceph的工作原理和若干关键工作流程进行扼要介绍.如前所述,由于Ceph的功能实现本质上依托于RADOS,因而,此处的介绍事实上也是针对RADOS进行.对于上层的部分,特别是RADOS GW和 ...

  3. Spring官方文档

    官网里还真不好找,编译的时候pdf版还没编译成功,这里记录下 http://docs.spring.io/spring/

  4. stm32通信概述

    本文提到的内容有以下几个方面: 通信概述 串口通信 I2C通信 CAN通信 SPI通信 I2S通信 USB通信 其他通信 一.通信概述 按照数据传送方式分: 串行通信(一条数据线.适合远距离传输.控制 ...

  5. TabControl关闭选项卡

    关闭TabControl选项卡: Private Sub TabControl_Main_CloseButtonClick(sender As Object, e As EventArgs) Hand ...

  6. Shiro 权限校验不通过时,区分GET和POST请求正确响应对应的方式

    引入:https://blog.csdn.net/catoop/article/details/69210140 本文基于Shiro权限注解方式来控制Controller方法是否能够访问. 例如使用到 ...

  7. kali中的中国菜刀weevely

    weevely是一个kali中集成的webshell工具,是webshell的生成和连接集于一身的轻量级工具,生成的后门隐蔽性比较好,是随机生成的参数并且加密的,唯一的遗憾是只支持php,weevel ...

  8. 颜色模式中8位,16位,24位,32位色彩是什么意思?会有什么区别?计算机颜色格式( 8位 16位 24位 32位色)<转>

    颜色模式中8位,16位,24位,32位色彩是什么意思?会有什么区别简单地说这里说的位数和windows系统显示器设置中的颜色位数是一样的.表示的是能够显示出来的颜色的多少. 8位的意思是说,能够显示出 ...

  9. JBPM4.4学习笔记

    1.JBPM4表说明: JBPM4_DEPLOYMENT 流程定义表 JBPM4_DEPLOYPROP 流程定义属性表 JBPM4_EXECUTION 流程实例表 JBPM4_HIST_ACTINST ...

  10. python:while 语句的使用方法

    while语句: count = 0 while True: print(count) count += 1 if count == 10: break 实例: 计算n!,若:n = 5:则:n! = ...