题意:
给出旋转方向,询问何时数字可以重合
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
int a[10];
int b[10];
struct node{
int top,bottom,left,right,ft,bk;
int step;
node(int _top,int _bottom,int _left,int _right,int _ft,int _bk,int _step)
{
top=_top;
bottom=_bottom;
left=_left;
right=_right;
ft=_ft;
bk=_bk;
step=_step;
}
};
int vis[7][7][7][7][7][7];
bool flag(node x)
{
if(vis[x.top ][ x.bottom ][ x.left ][ x.right ][ x.ft ][ x.bk])
return false;
vis[x.top ][ x.bottom ][ x.left ][ x.right ][ x.ft ][ x.bk]=1;
return true;
}
bool judge(node x)
{
if( x.top==b[1]&&x.bottom==b[2]&&x.left==b[3]&&x.right==b[4]&&x.ft==b[5]&&x.bk==b[6] )
return true;
return false;
}
int bfs()
{
queue<node> q;
node tmp=node(a[1],a[2],a[3],a[4],a[5],a[6],0);
q.push(tmp);
flag(tmp);
while(!q.empty())
{
node tp=q.front();
q.pop();
if(judge(tp))
{
return tp.step;
}
tmp=tp;
tmp.step++;
tmp.top=tp.right;
tmp.bottom=tp.left;
tmp.left=tp.top;
tmp.right=tp.bottom;
if(flag(tmp))
q.push(tmp);
tmp=tp;
tmp.step++;
tmp.top=tp.left;
tmp.bottom=tp.right;
tmp.left=tp.bottom;
tmp.right=tp.top;
if(flag(tmp))
q.push(tmp);
tmp=tp;
tmp.step++;
tmp.top=tp.bk;
tmp.bottom=tp.ft;
tmp.ft=tp.top;
tmp.bk=tp.bottom;
if(flag(tmp))
q.push(tmp);
tmp=tp;
tmp.step++;
tmp.top=tp.ft;
tmp.bottom=tp.bk;
tmp.ft=tp.bottom;
tmp.bk=tp.top;
if(flag(tmp))
q.push(tmp);
}
return -1;
}
int main(){
while(~scanf("%d%d%d%d%d%d",a+1,a+2,a+3,a+4,a+5,a+6))
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=6;i++)
scanf("%d",&b[i]);
printf("%d\n",bfs());
}
}