zoukankan      html  css  js  c++  java
  • 纸牌三角形


    标题:纸牌三角形

    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;
                }
            
            }
        }
    }
  • 相关阅读:
    hdu 5151 Sit sit sit
    hdu 5150 Sit sit sit
    cf C. Arithmetic Progression
    hdu 5125 magic balls
    Pots(bfs)
    Prime Path(素数筛选+bfs)
    A Knight's Journey(dfs)
    Colored Sticks (字典树哈希+并查集+欧拉路)
    Squares(哈希)
    Gold Balanced Lineup(哈希表)
  • 原文地址:https://www.cnblogs.com/jizhidexiaobai/p/8583437.html
Copyright © 2011-2022 走看看