## sicily 1215 脱离地牢 原

Ciel

### Description

Pairs仔细分析了地图，他找出了一条最快的行走方案，最终与Helen相聚。他们一起念出了咒语"@^&#……%@%&\$"，轰隆一声，地牢塌陷了，他们又重见光明……

### Sample Input

``````5 5
#####
#H..#
#.!.#
#.#P#
#####
WNSE``````

### Sample Output

``````5

## 代码：

``````// Problem#: 1215
// Submission#: 1854023
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

#define MAX 20
int n, m;

struct state{
int P_x, P_y, H_x, H_y;
int step;
bool same(){
return P_x == H_x && P_y == H_y;
}
bool judge(){
return P_x > 0 && P_x <= n &&  P_y > 0 && P_y <= m
&& H_x > 0 && H_x <= n && H_y > 0 && H_y <= m ;
}
bool ismeet(state s){
return P_x == s.H_x && P_y == s.H_y && H_x == s.P_x && H_y == s.P_y;
}
state(int P_x, int P_y, int H_x, int H_y) {
this->H_x = H_x; this->H_y = H_y; this->P_x = P_x; this->P_y = P_y; step = 0;
}
state() {
step = 0;
}
};

enum direction{N, S, W, E};

int move[4][2] = {{-1, 0},{1, 0}, {0, -1}, {0, 1}};
int match[4];
char _mape[MAX][MAX];
bool visit[MAX][MAX][MAX][MAX];

int P_x, P_y, H_x, H_y;

void bfs();

int main(){
char c;
while (cin >> n >> m){
memset(visit, false, sizeof(visit));

for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
cin >> _mape[i][j];
if (_mape[i][j] == 'P'){
P_x = i;
P_y = j;
_mape[i][j] = '.';
}
if (_mape[i][j] == 'H'){
H_x = i;
H_y = j;
_mape[i][j] = '.';
}
}

for (int i = 0; i < 4; i++){
cin >> c;
switch (c){
case 'N':
match[i] = N;
break;
case 'S':
match[i] = S;
break;
case 'W':
match[i] = W;
break;
case 'E':
match[i] = E;
break;
}
}
bfs();
}
return 0;
}

void bfs(){
queue <state> buffer;
buffer.push(state(P_x, P_y, H_x, H_y));

state temp, next;

while (!buffer.empty()){
temp = buffer.front();
buffer.pop();
if (temp.step > 255){
cout << "Impossible" << endl;
return;
}
for (int i = 0; i < 4; i++){
next.P_x = temp.P_x + move[i][0];
next.P_y = temp.P_y + move[i][1];
next.H_x = temp.H_x + move[match[i]][0];
next.H_y = temp.H_y + move[match[i]][1];
next.step = temp.step + 1;

if (next.judge() && _mape[next.H_x][next.H_y] != '!'
&& _mape[next.P_x][next.P_y] == '.' ){
if (_mape[next.H_x][next.H_y] == '#'){
next.H_x -= move[match[i]][0];
next.H_y -= move[match[i]][1];
}
if (!visit[next.P_x][next.P_y][next.H_x][next.H_y]){
visit[next.P_x][next.P_y][next.H_x][next.H_y] = true;
if (next.same() || temp.ismeet(next)){
cout << next.step << endl;
return ;
}
else
buffer.push(next);
}
}
}

}
cout << "Impossible" << endl;
}``````

### Ciel

--============Oracle ADG搭建============== --==========准备阶段========= 1.检查primary为archivelog模式。 select log_mode from v\$database; 如果为noarchivelog模式，切换到archivelo......

UltraSQL
2018/07/23
0
0
POJ 2251 Dungeon Master

Dungeon Master 　　You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It tak......

suvvm
2018/12/06
0
0
nginx反向代理iis下的asp.net网站报错，急！！！！

2015/11/23
1K
2
codecombat之边远地区的森林23-30关及地牢40\41关代码分享

codecombat中国游戏网址：http://www.codecombat.cn/ 所有代码为javascript代码分享 23、Agrippa防守 loop { var enemy = this.findNearestEnemy(); if(enemy) { // 用 distanceTo 获取与敌人......

comA
2015/08/26
0
0

c-ys
2015/12/09
24
0

iOS Xcode升级包地址（感谢大神）

_____1____
10分钟前
4
0
Qt编写自定义控件71-圆弧进度条

10分钟前
3
0

22分钟前
4
0
【1015】LNMP架构二

【1015】LNMP架构二 三、PHP安装 PHP安装和LAMP安装PHP方法有差别，需要开启php-fpm服务 1、下载PHP7至/usr/local/src/ 切换目录：cd /usr/local/src 2、解压缩 tar -jxvf php-7.3.0.tar.gz...

56分钟前
5
0

6
0