/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
int n, m;
char s[205][205];
int sx, sy;
int vis[205][205];
int dist[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
struct node
{
int x, y, step;
bool operator <(const node &a)const{
return step > a.step;
}
};
void bfs(){
memset(vis, 0, sizeof(vis));
priority_queue<node>q;
q.push(node{sx, sy, 0});
vis[sx][sy] = 0;
while(q.size()){
node u = q.top();
q.pop();
for (int i = 0; i < 4; i++){
int x = u.x + dist[i][0], y = u.y + dist[i][1];
if(x < 1 || x > n || y < 1 || y > m || s[x][y] == '#') continue;
if(s[x][y] == 'a'){
printf("%d\n", u.step + 1);
return ;
}
if(s[x][y] == 'x'){
if(!vis[x][y] || vis[x][y] > u.step + 2){
vis[x][y] = u.step + 2;
q.push(node{x, y, vis[x][y]});
}
}else{
if(!vis[x][y] || vis[x][y] > u.step + 1){
vis[x][y] = u.step + 1;
q.push(node{x, y, vis[x][y]});
}
}
}
}
printf("Poor ANGEL has to stay in the prison all his life.\n");
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(scanf("%d %d", &n, &m) == 2){
for (int i = 1; i <= n; i++){
scanf("%s", s[i] + 1);
for (int j = 1; j <= m; j++){
if(s[i][j] == 'r'){
sx = i, sy = j;
break;
}
}
}
bfs();
}
return 0;
}
/**/
我以为是啥多个起点走到同一个终点,然后在想一个guard只能被杀一次,用优先队列表示路径然后把杀死的变成畅通的路,结果发现是一个起点,哎,气死了