博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4.2.7 Waiting ten thousand years for Love
阅读量:5162 次
发布时间:2019-06-13

本文共 4640 字,大约阅读时间需要 15 分钟。

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 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.
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.

思路:BFS,看了别人的AC代码,终于开始用优先队列了!那么优先队列是个什么东东呢?先自己百度,就说可以把队列中的元素按一定顺序排列,好好啊!

有一些细节错误害得我检查了好久!

1 #include 
2 #include
3 #include
4 using namespace std; 5 6 struct qq 7 { 8 int x,y,step,p; 9 bool friend operator < (const qq &a,const qq &b) 10 { 11 if (a.step==b.step) 12 return a.p
b.step; 14 } 15 } s,ya; 16 17 priority_queue
q; 18 19 const int dx[]={
1,-1,0,0}; 20 const int dy[]={
0,0,1,-1}; 21 bool f[82][82][82]; 22 char map[82][82]; 23 int power,t,n,m,ax,ay,i,cnt=0,tot=0; 24 25 bool pd() 26 { 27 if (map[ya.x][ya.y]=='#') return true; //也就是不能到达,直接退出 28 if (ya.x>=0 && ya.x
=0 && ya.y
0) //也就是说这一步是可以用能量的 36 for (i=0;i<4;i++) 37 { 38 ya.x=s.x+dx[i]; 39 ya.y=s.y+dy[i]; 40 ya.p=s.p-1; //能量减少1 41 ya.step=s.step; 42 if (not pd()) 43 { 44 f[ya.x][ya.y][ya.p]=true; 45 ya.step++; //步数增加1 46 q.push(ya); 47 } 48 } 49 if (map[s.x][s.y]=='@') return; //在@的时候,如果不能移动,则挂了 50 for (i=0;i<4;i++) 51 { 52 ya.x=s.x+dx[i]; 53 ya.y=s.y+dy[i]; 54 ya.p=s.p; 55 ya.step=s.step; //这一句一定要加上,否则就未清零啊! 56 if (not pd() && ( map[ya.x][ya.y]=='.' || map[ya.x][ya.y]=='L' )) 57 { 58 f[ya.x][ya.y][ya.p]=true; //这句话把我整惨了! 59 ya.step+=2; 60 q.push(ya); 61 } 62 } 63 } 64 65 void bfs() 66 { 67 memset(f,false,sizeof(f)); 68 while (!q.empty()) 69 q.pop(); 70 s.x=ax; s.y=ay; s.p=power; s.step=0; 71 f[s.x][s.y][s.step]=true; 72 q.push(s); 73 while (!q.empty()) 74 { 75 s=q.top(); 76 q.pop(); 77 if (map[s.x][s.y]=='#') break; 78 if (map[s.x][s.y]=='L') 79 { 80 if (t>=s.step) 81 printf("Yes, Yifenfei will kill Lemon at %d sec.\n",s.step); 82 else printf("Poor Yifenfei, he has to wait another ten thousand years.\n"); 83 return; 84 } 85 judge(); 86 } 87 printf("Poor Yifenfei, he has to wait another ten thousand years.\n"); 88 } 89 90 91 void init() 92 { 93 while (scanf("%d%d%d%d",&n,&m,&t,&power)!=EOF) 94 { 95 cnt++; 96 printf("Case %d:\n",cnt); 97 for(int i=0;i

 

转载于:https://www.cnblogs.com/cssystem/archive/2012/12/25/2833197.html

你可能感兴趣的文章
Nginx反向代理的基本配置
查看>>
SpringMvc文件资源防止被外链链接
查看>>
WCF、WebAPI、WCFREST、WebService之间的区别
查看>>
设计模式 -- 单例模式
查看>>
Linux下安装 php imagick扩展
查看>>
git出现: not a git repository
查看>>
appium 问题
查看>>
go条件语句
查看>>
css使用的三种方式
查看>>
C#中Const和Readonly的区别
查看>>
Noip2016day2 组合数问题problem
查看>>
django中widget小部件
查看>>
训练记录
查看>>
使用 Windows Live ID 登录 Windows 8---------互联网时代的云端革命
查看>>
横屏模式注意点
查看>>
虚拟机对网卡的设置
查看>>
after()和inserAfter(),before()和inserBefore()区别
查看>>
JDBC——释放资源的代码
查看>>
bootstrap模态框垂直居中
查看>>
用数据管理过程(3)——可预测级别的量化管理(麦当劳的管理方式)
查看>>