The main idea: go to the maze, the wall when you can push the wall to walk, but the wall behind the wall and cannot be pushed. Find an arbitrary shortest path.
Topic Analysis: The problem of the comparison of human nature, when the input is the surrounding wall with a binary number is expressed well, in fact, so as to alleviate the burden of the problem. ida*, when the distance to the nearest exit plus the current number of layers cur is larger than maxd, then prune. However, it is worth noting that when pushing the wall away, it involves changes in the walls around the 3 squares (except at the boundary).
The code is as follows:
# include<iostream># include<cstdio># include<cmath># include<vector># include<cstring ># include<algorithm>using namespace std;struct xy{int x, y; XY (int _x,int _y): X (_x), Y (_y) {}};vector<xy>xy;int mp[4][6],sx,sy;int d[4][2]={{0,-1},{-1,0},{0,1},{1,0}};int Dd[4]={2,3,0,1};string pd= "Wnes", Ans;void F () {xy.clear (); for (int i=0;i<6;++i) {if ((mp[0][i]&2) ==0) xy.push_back (XY (0,i)); if ((mp[3][i]&8) ==0) xy.push_back (XY (3,i)); } for (int i=0;i<4;++i) {if ((mp[i][0]&1) ==0) xy.push_back (XY (i,0)); if ((mp[i][5]&4) ==0) xy.push_back (XY (i,5)); }}bool dfs (int cur,int maxd,int x,int y,string path) {if (Cur==maxd) {if (x==0&& ((mp[x][y]&2) ==0)) { ans=path+ ' N '; return true; } if (x==3&& (mp[x][y]&8) ==0) {ans=path+ ' S '; return true; } if (y==0&& (mp[x][y]&1) (==0)) {ans=path+ ' W '; return true; } if (y==5&& (mp[x][y]&4) ==0) {ans=path+ ' E '; return true; } return false; } f (); int minn=10000,l=xy.size (); for (int i=0;i<l;++i) minn=min (Minn,abs (x-xy[i].x) +abs (Y-XY[I].Y)); if (Cur+minn>maxd) return false; for (int i=0;i<4;++i) {int nx=x+d[i][0],ny=y+d[i][1]; if (nx<0| | nx>3| | ny<0| | NY>5) continue; if (mp[x][y]& (1<<i)) {if (mp[nx][ny]& (1<<i)) continue; Mp[x][y]^= (1<<i); Mp[nx][ny]^= (1<<dd[i]); Mp[nx][ny]^= (1<<i); int nnx=nx+d[i][0],nny=ny+d[i][1]; if (nnx>=0&&nnx<4&&nny>=0&&nny<6) mp[nnx][nny]^= (1<<dd[i]); if (Dfs (Cur+1,maxd,nx,ny,path+pd[i])) return true; mp[nx][ny]^=(1<<i); Mp[nx][ny]^= (1<<dd[i]); Mp[x][y]^= (1<<i); if (nnx>=0&&nnx<4&&nny>=0&&nny<6) mp[nnx][nny]^= (1<<dd[i]); }else{if (Dfs (Cur+1,maxd,nx,ny,path+pd[i])) return true; }} return false;} int main () {//freopen ("UVA-10384 the Wall Pushers.txt", "R", stdin); while (scanf ("%d%d", &sy,&sx) && (Sx+sy)) {--sx,--sy; for (int i=0;i<4;++i) for (int j=0;j<6;++j) scanf ("%d", &mp[i][j]); for (int maxd=0;; ++maxd) {if (Dfs (0,maxd,sx,sy, "")) {cout<<ans<<endl; Break }}} return 0;}
UVA-10384 the Wall pushers (ida*)