#include <iostream>
#include <queue>
using namespace std;
int a[11],b[30]={},sum=0,cs=0;
int wt[11][5]={{0},{1,2,4,5,0},{1,2,3,0,0},{2,3,5,6,0},{1,4,7,0,0},{2,4,5,6,8},{3,6,9,0,0},{4,5,7,8,0},{7,8,9,0,0},{5,6,8,9,0}};
bool vis[5][5][5][5][5][5][5][5][5]={};
struct w{
int hh[11];
int oo[30];
int n;
};
queue<w>q;
bool ch(w c) {
for(int i=1 ;i<=9 ;i++) {
if(c.hh[i]!=0) {
return false;
}
}
return true;
}
w mv(w f,int n) {
for(int i=0 ;i<5 ;i++) {
f.hh[wt[n][i]]=(f.hh[wt[n][i]]+3)%4;
}
f.n++;
f.oo[f.n]=n;
return f;
}
void bfs() {
q.push(w{a,b,0}); //这里哦
w next,now;
while(!q.empty()) {
now=q.front();
q.pop();
for(int i=1 ;i<=9 ;i++) {
next=mv(now,i);
if(ch(next)) {
for(int j=1 ;j<=now.n ;j++) {
cout<<now.oo[j];
}
cout<<i<<endl;
return ;
}
if(vis[next.hh[1]][next.hh[2]][next.hh[3]][next.hh[4]][next.hh[5]][next.hh[6]][next.hh[7]][next.hh[8]][next.hh[9]]) {
continue;
}
vis[next.hh[1]][next.hh[2]][next.hh[3]][next.hh[4]][next.hh[5]][next.hh[6]][next.hh[7]][next.hh[8]][next.hh[9]]=true;
q.push(next);
}
}
}
int main() {
for(int i=1 ;i<=9 ;i++) {
cin>>a[i];
a[i]%=4;
}
bfs();
return 0;
}
Dev和洛谷都编译不过去啊……