暴力。
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int CLOCKS = 9;
const int move[CLOCKS][CLOCKS] =
{
{1, 1, 0, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 1, 0, 1, 1, 1, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 1, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 0, 1, 1},
};
int clock[CLOCKS];
int op[CLOCKS];
vector<int> ans;
void read_clock()
{
for (int i = 0; i < CLOCKS; i++)
scanf("%d", &clock[i]);
}
int is_ok()
{
static int temp[CLOCKS];
for (int i = 0; i < CLOCKS; i++)
temp[i] = clock[i];
for (int i = 0; i < CLOCKS; i++)
{
for (int j = 0; j < CLOCKS; j++)
temp[j] += op[i] * move[i][j];
}
for (int i = 0; i < CLOCKS; i++)
if (temp[i] % 4)
return 0;
int cnt = 0;
for (int i = 0; i < CLOCKS; i++)
cnt += op[i];
return cnt;
}
void _dfs(int x)
{
int sz;
if (sz = is_ok())
{
if (sz < ans.size() || !ans.size())
{
ans.clear();
for (int i = 0; i < CLOCKS; i++)
{
for (int j = 0; j < op[i]; j++)
ans.push_back(i+1);
}
}
return;
}
if (x >= 8)
return;
for (int i = 0; i < 4; i++)
{
op[x+1] = i;
_dfs(x+1);
}
}
void _print()
{
for (int i = 0; i < ans.size(); i++)
printf("%d ", ans[i]);
}
int main()
{
read_clock();
_dfs(-1);
_print();
return 0;
}