移动方向表示:你的移动方向用小写字母{e,w,s,n}分别表示(右,左,下,上)
推箱子的移动方向用大写字母{E,W,S,N}分别表示(右,左,下,上)下面几行表示m*n的一个房间。
【输出文件】
输出文件taoli.out
输出最快的移动步骤。
eennwwWWWWeeeeeesswwwwwwwnNN
const x:array[1..4]of longint=(1,-1,0,0); y:array[1..4]of longint=(0,0,1,-1); var a:array[0..51,0..51]of char; p:array[0..51,0..51,0..51,0..51]of 0..1; f,x1,y1,x2,y2:array[1..100000]of longint; step:array[1..100000]of char; n,m,i,j,t,w,l,r,u,v,k,x3,y3:longint; s:ansistring; function move(x:longint):char; begin if x=1 then exit('s'); if x=2 then exit('n'); if x=3 then exit('e'); if x=4 then exit('w'); end; begin readln(n,m); for i:=1 to n do begin for j:=1 to m do begin read(a[i,j]); if a[i,j]='I' then begin x1[1]:=i; y1[1]:=j; end; if a[i,j]='B' then begin x2[1]:=i; y2[1]:=j; end; if a[i,j]='X' then begin x3:=i; y3:=j; end; end; readln; end; t:=0;w:=1;p[x1[1],y1[1],x2[1],y2[1]]:=1; while t<w do begin inc(t); if(x2[t]=x3)and(y2[t]=y3) then begin k:=t; s:=''; while f[k]<>0 do begin s:=s+step[k]; k:=f[k]; end; for i:=length(s) downto 1 do write(s[i]); halt; end; l:=x1[t]; r:=y1[t]; for i:=1 to 4 do begin u:=l+x[i]; v:=r+y[i]; if(u>=1)and(u<=n)and(v>=1)and(v<=m)and(a[u,v]<>'1') then begin if(u<>x2[t])or(v<>y2[t]) then begin if p[u,v,x2[t],y2[t]]=0 then begin inc(w); x1[w]:=u; y1[w]:=v; x2[w]:=x2[t]; y2[w]:=y2[t]; step[w]:=move(i); f[w]:=t; p[x1[w],y1[w],x2[w],y2[w]]:=1; end; end; if(u=x2[t])and(v=y2[t]) then begin if(p[u,v,x2[t]+x[i],y2[t]+y[i]]=0)and(x2[t]+x[i]>=1) and(x2[t]+x[i]<=n)and(y2[t]+y[i]>=1)and(y2[t]+y[i]<=m) and(a[x2[t]+x[i],y2[t]+y[i]]<>'1') then begin inc(w); x1[w]:=u; y1[w]:=v; x2[w]:=x2[t]+x[i]; y2[w]:=y2[t]+y[i]; step[w]:=upcase(move(i)); f[w]:=t; p[x1[w],y1[w],x2[w],y2[w]]:=1; end; end; end; end; end; end.