枚举4^9次
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
int CLOCK[9],temp[9];
int enu[9]= {0},result[9];
char cycle[9][10]= {"ABDE","ABC","BCEF","ADG","BDEFH","CFI","DEGH","GHI","EFHI"};
int MIN=1000;
bool test() {
bool flag=true;
for(int i=0; i<9; i++)
if(temp[i]!=0) {
flag=false;
break;
}
return flag;
}
int main() {
for(int i=0; i<9; i++) scanf("%d",&CLOCK[i]);
for(int a=0; a<4; a++)
for(int b=0; b<4; b++)
for(int c=0; c<4; c++)
for(int d=0; d<4; d++)
for(int e=0; e<4; e++)
for(int f=0; f<4; f++)
for(int g=0; g<4; g++)
for(int h=0; h<4; h++)
for(int l=0; l<4; l++) {
int k=0;//拨钟次数
memcpy(temp,CLOCK,sizeof(int)*9);
enu[0]=a;
enu[1]=b;
enu[2]=c;
enu[3]=d;
enu[4]=e;
enu[5]=f;
enu[6]=g;
enu[7]=h;
enu[8]=l;
for(int i=0; i<9; i++) {//拨钟
int t=enu[i];
while(t--) {
k++;
for(int j=0; cycle[i][j]!=0; j++) temp[cycle[i][j]-'A']=(temp[cycle[i][j]-'A']+1)%4;
}
}
if(k<MIN&&test()) {
MIN=k;
memcpy(result,enu,sizeof(int)*9);
}
}
for(int i=0; i<9; i++) while(result[i]--) printf("%d ",i+1);
return 0;
}