注意逻辑顺序
#include <cstdio>
#include <iostream>
using namespace std;
bool success(int* a)
{
for (int i = 0; i < 9; i++)
{
if (a[i] != 0)
return false;
}
return true;
}
int main()
{
int clk[10];
for (int i = 0; i < 9; i++)
scanf("%d", &clk[i]);
if (success(clk))
{
cout << '0' << endl;
return 0;
}
int min = 10000;
int count[9] = {};
int a[9][9] =
{
{ 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 p0, p1, p2, p3, p4, p5, p6, p7, p8;
for ( p0 = 0; p0 < 4; p0++)
for ( p1 = 0; p1 < 4; p1++)
for ( p2 = 0; p2 < 4; p2++)
for ( p3 = 0; p3 < 4; p3++)
for ( p4 = 0; p4 < 4; p4++)
for ( p5 = 0; p5 < 4; p5++)
for ( p6 = 0; p6 < 4; p6++)
for ( p7 = 0; p7 < 4; p7++)
for ( p8 = 0; p8 < 4; p8++)
{
bool success = true;
/*if (p2 == 1 && p4 == 1 && p6 == 1)
{
cout << "fuck!" << endl;
}*/
for (int i = 0; i < 9; i++)
{
if ((clk[i] + a[0][i] * p0 + a[1][i] * p1 + a[2][i] * p2 + a[3][i] * p3 +
a[4][i] * p4 + a[5][i] * p5 + a[6][i] * p6 + a[7][i] * p7 + a[8][i] * p8) % 4 != 0)
{
success = false;
break;
}
}
if (success)
{
int num;
num = p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
if (num < min)
{
min = num;
count[0] = p0; count[1] = p1; count[2] = p2;
count[3] = p3; count[4] = p4; count[5] = p5;
count[6] = p6; count[7] = p7; count[8] = p8;
}
}
}
//cout << p0 << " " << p1 << " " << p2 << " " << p3 << " " << p4 << " " << p5 << " " << p6 << " " << p7 << " " << p8 << endl;
for (int i = 0; i < 9; i++)
{
while (count[i]--)
{
printf("%d ", i + 1);
}
}
return 0;
}