标题:纸牌三角形
A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下图就是一种排法(如有对齐问题,参看p1.png)。
A
9 6
4 8
3 7 5 2
这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
请你计算并提交该数字。
注意:需要提交的是一个整数,不要提交任何多余内容。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
这题用暴力解法比较省时间而且不容易出错
public static void main(String[] args) {
int count=0;
//十层循环分别代表每一个数字
for (int a = 1; a <10; a++) {
for (int b = 1; b < 10; b++) {
for (int c = 1; c <10; c++) {
for (int d =1; d < 10; d++) {
for (int e = 1; e < 10; e++) {
for (int f = 1; f <10; f++) {
for (int g =1; g < 10; g++) {
for (int h =1; h < 10; h++) {
for (int i =1; i < 10; i++) {
//十个数字互不相等
if (a!=b && a!=c && a!=d && a!=e && a!=f && a!=g && a!=h && a!=i &&
b!=c && b!=d && b!=e && b!=f && b!=g && b!=h && b!=i &&
c!=d && c!=e && c!=f && c!=g && c!=h && c!=i &&
d!=e && d!=f && d!=g && d!=h && d!=i &&
e!=f && e!=g && e!=h && e!=i &&
f!=g && f!=h && f!=i &&
g!=h && g!=i &&
/ /按照题意三个面互相相等
h!=i&a+b+d+f==a+c+e+i&a+c+e+i==f+g+h+i&f+g+h+i==a+b+d+f) {
count++;
}
}}}}}}}}
//算上镜像和倒转一共有六种相同
}System.out.println(count/6);
}