第一层bfs找箱子移动的最短路,第二层找人到箱子后边位置的最短路。
难点可能是第一层bfs的vis数组需要开三维,需要同时记录走过点的方向。
其实字符串的处理,路径输出也很恶心。。。属于稍微有点错就得调半天那种
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
const int maxn = 25, inf = 0x7fffffff;
const int nxt[4][2] = {-1,0,1,0,0,-1,0,1};
const char O[4] = {'N','S','W','E'};
const char o[4] = {'n','s','w','e'};
struct Node
{
int x,y,px,py;
string ans;
Node(int x=0,int y=0):x(x),y(y){}
}st;
int n,m,vis1[maxn][maxn][4],vis2[maxn][maxn];
char map[maxn][maxn];
string tmp;
queue<Node> q1,q2;
inline int judge(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= m && map[x][y] != '#';
}
inline int bfs2(Node p1,Node p2)
{
memset(vis2,0,siz