hdu2653之BFS
来源:互联网 发布:数据库not exists子句 编辑:程序博客网 时间:2024/06/05 17:03
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.
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 2Y@L###2 3 4 1Y@L###2 3 4 0Y.L###2 3 3 0Y.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.HintHintCase 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 99999999using 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
- hdu2653
- 09-05 HDU_Steps4.2 BFS HDU1242 HDU1548 HDU1372 HDU1728 HDU1252 HDU2612 HDU2653 HDU2531
- hdu2653(Steps 4.2.8)
- 【BFS】魔鬼之城
- hdu1429之BFS
- hdu2531之BFS
- hdu2579之BFS
- hdu2364之BFS
- hdu2216之BFS
- hdu1547之BFS
- hdu2102之BFS
- hdu2128之BFS
- hdu4308之BFS
- hdu2757之BFS
- 算法入门之BFS
- 搜索专题之BFS
- 实现BFS之“营救”
- 找新朋友
- 内存cookie与持久cookie
- org.apache.jasper.jasperexception the struts dispatcher cannot be found
- UVa 133 - The Dole Queue
- loner_li 产生一个长度为100的数组,为数组中的每一项随机填充1-100之间的数并且保证不重复
- hdu2653之BFS
- 使用ffmpeg+crtmpserver搭建文件的伪直播
- Python thread的解析
- poj 1523 SPF 无向图求割点
- ZOJ3705:Applications
- 黑马程序员-------超市库存管理系统需求说明书
- UVa 11027 - Palindromic Permutation(排列编码)
- 实例恢复时间
- CSRF攻击方式-跨站请求伪造攻击