A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下图就是一种排法这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
输出
输出一个整数表示答案
思路:对9个数全排列,注意去重(翻转3次,镜像2次)
#include <iostream>
#include <algorithm>
using namespace std;
int a[9] = {1,2,3,4,5,6,7,8,9};
bool check()
{
int x1 = a[0] + a[1] + a[2] + a[3];
int x2 = a[3] + a[4] + a[5] + a[6];
int x3 = a[6] + a[7] + a[8] + a[0];
if (x1 == x2 && x2 == x3) return true;
return false;
}
int main()
{
int res = 0;
do
{
if (check()) res++;
}while (next_permutation(a,a + 9));
cout << res / 6<< endl;
}