问题描述
如下图所示六角形中,填入1~12的数字。
使得每条直线上的数字之和都相同。
图中,已经替你填好了 3 个数字,请你计算星号位置所代表的数字是多少?
答案提交
请通过浏览器提交答案,不要填写多余的内容。
答案:10
解题思路:
题解
全排列:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[9] = {2, 4, 5, 6, 7, 9, 10, 11, 12};
do
{
int L1 = 1 + a[0] + a[3] + a[5];
int L2 = 1 + a[1] + a[4] + a[8];
int L3 = a[5] + a[6] + a[7] +a[8];
int L4 = 8 + a[0] + a[1] + a[2];
int L5 = 8 + a[3] + a[6] + 3;
int L6 = a[2] + a[4] + a[7] + 3;
if(L1 == L2 && L1 == L3 && L1 == L4 && L1 == L5 && L1 == L6) cout << a[3] << endl;
}while(next_permutation(a, a + 9));
return 0;
}