Waiting ten thousand Years for Love
Time limit:10000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1057 Accepted Submission (s): 335
Problem DescriptionIt was ten thousand years, after Demon Lemon caught Yifenfei ' s love. In order to revenge and save he Love, Yifenfei has been practising sword all day long and he kongfu skills becomes so p Owerful that he can kill Demon Lemon immediately. Recently, Yifenfei has found Lemon ' s castle, and now he's going to kill Lemon. At the same time, hearing about the terrible news, Demon Lemon was now preparing for escaping ...
Now Yifenfei has got the map of the castle.
Here is 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 isn't walk on it, but can fly over it.
Yifenfei can walk or fly to one of the up, down, left or right four directions each step, walk costs him 2 seconds per step, f Ly costs him 1 second per step and 1 magic power. His magic power would not be increased, and if his magic power was zero, he can not fly any more.
Now Yifenfei asks your for helping him kill Demon Lemon smoothly. At the same time, Demon Lemon would Leave the castle Atfer T seconds. If Yifenfei can ' t kill Demon Lemon This time, he has to wait another ten thousand years.
Inputlots of test cases, please process to end of file. In each test case, firstly'll has four integers n, m, T, p (1 <= N, M, p <=, 1 <= T <= 100000), indicates The size of map N * M, the Lemon ' s leaving time (after T seconds, Lemon'll disappeared) and Yifenfei ' s magic power. Then an N * M two-dimensional array follows indicates the map.
Outputfor 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 would kill Lemon at T sec.", T indicates the Mini Mum seconds he must cost. Otherwise, Print "Poor Yifenfei, he had to wait another ten thousand years."
Sample Input2 3 2 2[email protected]## #2 3 4 1[email protected]## #2 3 4 0Y. l## #2 3 3 0Y. l###
Sample outputcase 1:yes, Yifenfei would kill Lemon at 2 sec. Case 2:poor Yifenfei, he had to wait another ten thousand years. Case 3:yes, Yifenfei would kill Lemon at 4 sec. Case 4:poor Yifenfei, he had 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 had no power to Fly, and was killed by trap.
Authorlemon
Source Battle Dragon humen test instructions: N row m-column map, start position y, end position L, #代表墙不能走, @ for trap must fly past two consecutive fly to pass a trap. Representative road can go past can also fly past, bit in time t to arrive and ask the shortest time, fly past with 1 seconds, Walk over for 2 seconds, fly one time to consume 1 mana, a total of P-point magic value. Code:
1 //card for a long time, and later found that other people's solving vis is three-dimensional. 2 //obviously to use the priority queue, the subject of the VIS is not only visited once, can access p times, because the different energy values through the same point of the scheme must be different. 3#include <iostream>4#include <cstdio>5#include <cstring>6#include <queue>7 using namespacestd;8 intn,m,t,p;9 Charmap[ the][ the];Ten BOOLvis[ the][ the][ the]; One intdir[4][2]={1,0,-1,0,0,1,0,-1}; A structLu - { - intX,y,cnt,mag; theFriendBOOL operator<(Lu a,lu b) - { - returnA.cnt>b.cnt; - } + }; - intBFsintSxintSy) + { APriority_queue<lu>Q; at Lu l1,l2; -L1.X=SX; L1.y=sy; L1.cnt=0; l1.mag=p; -vis[sx][sy][p]=1; - Q.push (L1); - while(!q.empty ()) - { inL2=q.top (); - Q.pop (); to if(l2.cnt>t) + return 10000000; - if(map[l2.x][l2.y]=='L') the returnl2.cnt; * for(intI=0;i<4; i++) $ {Panax Notoginsengl1.x=l2.x+dir[i][0]; -l1.y=l2.y+dir[i][1]; the if(l1.x<0|| l1.x>=n| | l1.y<0|| L1.Y>=M)Continue; + if(map[l1.x][l1.y]=='#')Continue; A if(l2.mag>0&&!vis[l1.x][l1.y][l2.mag-1]) the { +l1.cnt=l2.cnt+1; -l1.mag=l2.mag-1; $vis[l1.x][l1.y][l1.mag]=1; $ Q.push (L1); - } - if(map[l1.x][l1.y]!='@'&&map[l2.x][l2.y]!='@'&&!Vis[l1.x][l1.y][l2.mag]) the { -l1.cnt=l2.cnt+2;Wuyil1.mag=L2.mag; thevis[l1.x][l1.y][l2.mag]=1; - Q.push (L1); Wu } - } About } $ return 10000000; - } - intMain () - { A intsx,sy,k=0; + while(SCANF ("%d%d%d%d", &n,&m,&t,&p)! =EOF) the { -k++; $ for(intI=0; i<n;i++) the { thescanf"%s", Map[i]); the for(intj=0; j<m;j++) the if(map[i][j]=='Y') - { insx=i;sy=J; the } the } Aboutmemset (Vis,0,sizeof(Vis)); the intans=BFS (sx,sy); theprintf"Case %d:\n", k); the if(ans>t) printf ("Poor Yifenfei, he had to wait another ten thousand years.\n"); + Elseprintf"Yes, Yifenfei'll kill Lemon at%d sec.\n", ans); - } the return 0;Bayi}
HDU2653 bfs+ Priority Queue