CUBE 走迷宫,注意墙壁要双向都挡
//====================================================================||
// ||
// ||
// Author : GCA ||
// 6AE7EE02212D47DAD26C32C0FE829006 ||
//====================================================================||
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
using namespace std;
#ifdef ONLINE\_JUDGE
#define ll "%lld"
#else
#define ll "%I64d"
#endif
typedef unsigned int uint;
typedef long long int Int;
#define Set(a,s) memset(a,s,sizeof(a))
#define Write(w) freopen(w,"w",stdout)
#define Read(r) freopen(r,"r",stdin)
#define Pln() printf("\\n")
#define I\_de(x,n)for(int i=0;i<n;i++)printf("%d ",x\[i\]);Pln()
#define De(x)printf(#x"%d\\n",x)
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define Pmz(dp,nx,ny)for(int hty=0;hty<ny;hty++){for(int htx=0;htx<nx;htx++){\\
printf("%d ",dp\[htx\]\[hty\]);}Pln();}
#define M 55
#define PII pair<int,int\>
#define PB push\_back
#define oo INT\_MAX
#define Set\_oo 0x3f
#define Is\_debug true
#define debug(...) if(Is\_debug)printf("DEBUG: "),printf(\_\_VA\_ARGS\_\_)
#define FOR(it,c) for(\_\_typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define eps 1e-6
bool xdy(double x,double y){return x>y+eps;}
bool xddy(double x,double y){return x>y-eps;}
bool xcy(double x,double y){return x<y-eps;}
bool xcdy(double x,double y){return x<y+eps;}
int min3(int x,int y,int z){
int tmp=min(x,y);
return min(tmp,z);
}
int max3(int x,int y,int z){
int tmp=max(x,y);
return max(tmp,z);
}
int test;
int bx,by,ex,ey;
int nopass\[15\]\[15\]\[15\]\[15\];
int mz\[15\]\[15\]\[6\];
int dx\[4\]={0,0,1,-1};
int dy\[4\]={-1,1,0,0};
int dice\[6\]\[4\]={
{2,4,1,5},
{1,1,3,0},
{3,0,2,2},
{4,2,5,1},
{0,3,4,4},
{5,5,0,3}
};
int n,m;
struct node{
int x,y,side;
node(int x,int y,int side):x(x),y(y),side(side){};
node(){};
};
node bat\[15\]\[15\]\[6\];
void init(){
fill(&mz\[0\]\[0\]\[0\],&mz\[14\]\[14\]\[5\],oo);
Set(nopass,0);
}
void solve(){
queue<node> q;
q.push(node(bx,by,0));
mz\[bx\]\[by\]\[0\]=0;
while(!q.empty()){
node ntmp=q.front();q.pop();
int x=ntmp.x;
int y=ntmp.y;
int side=ntmp.side;
int step=mz\[x\]\[y\]\[side\];
// debug("%d %d %d %d\\n",x,y,side,step);
for(int i=0;i<4;i++){
int nx=x+dx\[i\],ny=y+dy\[i\];
if(nx>n||nx<1||ny>m||ny<1)continue;
int nside=dice\[side\]\[i\];
if(step+1<mz\[nx\]\[ny\]\[nside\]&&!nopass\[x\]\[y\]\[nx\]\[ny\]){
mz\[nx\]\[ny\]\[nside\]=step+1;
q.push(node(nx,ny,nside));
bat\[nx\]\[ny\]\[nside\]=node(x,y,side);
}
}
}
if(mz\[ex\]\[ey\]\[0\]==oo)printf("没有解决方案\\n");
else printf("%d\\n",mz\[ex\]\[ey\]\[0\]);
}
void backtra(int x,int y,int side){
int nx=bat\[x\]\[y\]\[side\].x;
int ny=bat\[x\]\[y\]\[side\].y;
int nside=bat\[x\]\[y\]\[side\].side;
if(x!=bx||y!=by||side!=0)
backtra(nx,ny,nside);
printf("%d %d %d\\n",x,y,side);
}
int main() {
ios\_base::sync\_with\_stdio(0);
scanf("%d",&test);
while(test--){
init();
scanf("%d%d%d%d%d%d%\*c",&n,&m,&bx,&by,&ex,&ey);
char c\[100\];
int choose;
while(gets(c)){
if(c\[0\]==''||c\[0\]=='\\n')break;
if(strcmp(c,"h")==0)choose=1;
else if(strcmp(c,"v")==0)choose=0;
else{
int x,y;
sscanf(c,"%d%d",&x,&y);
if(choose==0){
nopass\[x\]\[y\]\[x+1\]\[y\]=1;
nopass\[x+1\]\[y\]\[x\]\[y\]=1;
}
else{
nopass\[x\]\[y\]\[x\]\[y+1\]=1;
nopass\[x\]\[y+1\]\[x\]\[y\]=1;
}
}
}
solve();
if(test)Pln();
//backtra(ex,ey,0);
}
}