标题:六角填数
如图【1.png】所示六角形中,填入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;
}

本文介绍了一种使用全排列算法解决六角填数谜题的方法,目标是使六角形每条边上的数字之和相等。通过C++实现,找出星号位置所代表的数字。
1134

被折叠的 条评论
为什么被折叠?



