Loading

纸牌三角形


标题:纸牌三角形

A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下图就是一种排法(如有对齐问题,参看p1.png)。

A
9 6
4 8
3 7 5 2

这样的排法可能会有很多。

如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?

请你计算并提交该数字。

注意:需要提交的是一个整数,不要提交任何多余内容。

public class Main {
    static int count;
    static int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    public static void main(String[] args) {
        f(a, 0);
        System.out.println(count / 6);
    }
    private static void f(int[] a, int step) {
        if(step == a.length - 1) {
            if(a[0] + a[1] + a[2] + a[3] == a[3] + a[4] + a[5] + a[6] && a[3] + a[4] + a[5] + a[6] == a[6] + a[7] + a[8] + a[0]) {
                count ++;
                return;
            }
        }
        for(int i = step; i < a.length; i ++) {
            {
                int x = a[i];
                a[i] = a[step];
                a[step] = x;
            }
            
            f(a, step + 1);
            
            {
            int x = a[i];
            a[i] = a[step];
            a[step] = x;
            }
        
        }
    }
}

 

posted @ 2018-03-16 17:03  机智的小白  阅读(890)  评论(0编辑  收藏  举报