这题和八数码和九数码太像了QAQ
实在不会就看我以前的题解吧
话说这题坑点还是挺多的
#include<bits/stdc++.h>
using namespace std;
const int Max=9*9*9*9*9*9*9;
int now[Max][8],come[Max],r[8],u[Max],Do[Max];
int ans[8];
bool boo[9][9][9][9][9][9][9];
int i,j,k,m,n,h=1,t=1,x;
int write(int x)
{
if(come[x]!=-1)write(come[x]);
if(Do[x]==1)cout<<"A";
if(Do[x]==2)cout<<"B";
if(Do[x]==3)cout<<"C";
return 0;
}
int main()
{
for(i=0;i<8;i++)cin>>ans[i];
h=1;t=1;u[1]=0;
for(k=0;k<8;k++)now[h][k]=k+1;
boo
[now[t][0]]
[now[t][1]]
[now[t][2]]
[now[t][3]]
[now[t][4]]
[now[t][5]]
[now[t][6]]=true;
come[1]=-1;
while(t<=h)
{
if(now[t][0]==ans[0]
&&now[t][1]==ans[1]
&&now[t][2]==ans[2]
&&now[t][3]==ans[3]
&&now[t][4]==ans[4]
&&now[t][5]==ans[5]
&&now[t][6]==ans[6]
&&now[t][7]==ans[7])
{cout<<u[t]<<endl;write(t);return 0;}
r[0]=now[t][7];r[1]=now[t][6];r[2]=now[t][5];r[3]=now[t][4];//操作一
r[7]=now[t][0];r[6]=now[t][1];r[5]=now[t][2];r[4]=now[t][3];
/*
7654//操作一完成后的序列
0123
*/
if(!boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]])
{
h++;
for(k=0;k<=8;k++)now[h][k]=r[k];
come[h]=t;
Do[h]=1;
boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]]=true;
u[h]=u[t]+1;
}
r[0]=now[t][3];r[1]=now[t][0];r[2]=now[t][1];r[3]=now[t][2];//操作二
r[7]=now[t][4];r[6]=now[t][7];r[5]=now[t][6];r[4]=now[t][5];
/*
3012//操作二完成后的序列
4765
*/
if(!boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]])
{
h++;
for(k=0;k<=8;k++)now[h][k]=r[k];
come[h]=t;
Do[h]=2;
boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]]=true;
u[h]=u[t]+1;
}
r[0]=now[t][0];r[1]=now[t][6];r[2]=now[t][1];r[3]=now[t][3];//操作三
r[7]=now[t][7];r[6]=now[t][5];r[5]=now[t][2];r[4]=now[t][4];
/*
0613//操作三完成后的序列
7524
*/
if(!boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]])
{
h++;
for(k=0;k<=8;k++)now[h][k]=r[k];
come[h]=t;
Do[h]=3;
boo[r[0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]]=true;
u[h]=u[t]+1;
}
t++;
}
return 0;
}
QAQ