solution.cpp 655 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream>
#include <algorithm>

using namespace std;
int n[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int main()
{
    do
    {
        int line1 = n[0] + n[2] + n[5] + n[7];
        int line2 = n[0] + n[3] + n[6] + n[10];
        int line3 = n[7] + n[8] + n[9] + n[10];
        int line4 = n[1] + n[2] + n[3] + n[4];
        int line5 = n[1] + n[5] + n[8] + n[11];
        int line6 = n[4] + n[6] + n[9] + n[11];
        if (line1 == line2 && line2 == line3 && line3 == line4 && line4 == line5 && line5 == line6 && n[0] == 1 && n[1] == 8 && n[11] == 3)
            cout << n[5];

    } while (next_permutation(n, n + 12));

    return 0;
}