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


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即可,判断一下格子的状态。

#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,j,k) for (int i=j;i<=k;i++)
const int INF=0x7FFFFFFF;
const int sz=100;
int f[sz][sz][sz],mp[sz][sz];
int n,m,g,t,bx,by,ex,ey,T=0;
char s[sz][sz];
int x[4]={0,0,1,-1};
int y[4]={1,-1,0,0};

struct point
{
int x,y,z;
point(int x=0,int y=0,int z=0):x(x),y(y),z(z){};
};

int main()
{
while (~scanf("%d%d%d%d",&n,&m,&t,&g))
{
rep(i,1,n) rep(j,1,m) rep(k,0,g) f[i][j][k]=INF;
memset(mp,0,sizeof(mp));
rep(i,1,n)
{
scanf("%s",s[i]+1);
rep(j,1,m)
{
if (s[i][j]=='Y') {s[i][j]='.'; bx=i; by=j; }
if (s[i][j]=='L') {s[i][j]='.'; ex=i; ey=j; }
mp[i][j]=s[i][j]=='.'?1:s[i][j]=='@'?2:0;
}
}
queue<point> p;
p.push(point(bx,by,0)); f[bx][by][0]=0;
while (!p.empty())
{
point q=p.front(); p.pop();
if (q.z > g || f[q.x][q.y][q.z] > t || q.x==ex&&q.y==ey) continue;
rep(i,0,3)
{
int X=q.x+x[i],Y=q.y+y[i];
if (!mp[X][Y]) continue;
if (mp[q.x][q.y]==1&&mp[X][Y]==1)
{
if (f[X][Y][q.z]>f[q.x][q.y][q.z]+2)
{
f[X][Y][q.z]=f[q.x][q.y][q.z]+2;
p.push(point(X,Y,q.z));
}
if (f[X][Y][q.z+1]>f[q.x][q.y][q.z]+1)
{
f[X][Y][q.z+1]=f[q.x][q.y][q.z]+1;
p.push(point(X,Y,q.z+1));
}
}
else if (f[X][Y][q.z+1]>f[q.x][q.y][q.z]+1)
{
f[X][Y][q.z+1]=f[q.x][q.y][q.z]+1;
p.push(point(X,Y,q.z+1));
}
}
}
int flag=INF;
rep(i,0,g) flag=min(flag,f[ex][ey][i]);
printf("Case %d:\n",++T);
if (flag<=t) printf("Yes, Yifenfei will kill Lemon at %d sec.\n",flag);
else printf("Poor Yifenfei, he has to wait another ten thousand years.\n");
}
return 0;
}