纸牌三角形

标题:纸牌三角形

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

      A
     9 6
    4   8
   3 7 5 2


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


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


请你计算并提交该数字。


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

【解法一】

暴力循环

package com.sise.test;

public class Test01 {
	
	
	public static void main(String[] args){
		
		int count=0;
		
		for(int a=1;a<10;a++){
			for(int b=1;b<10;b++){
				if(a!=b){
					for(int c=1;c<10;c++){
						if(a!=c&&b!=c){
							for(int d=1;d<10;d++){
								if(a!=d&&b!=d&&c!=d){
									for(int e=1;e<10;e++){
										if(a!=e&&b!=e&&c!=e&&d!=e){
											for(int f=1;f<10;f++){
												if(a!=f&&b!=f&&c!=f&&d!=f&&e!=f){
													for(int g=1;g<10;g++){
														if(a!=g&&b!=g&&c!=g&&d!=g&&e!=g&&f!=g){
															for(int h=1;h<10;h++){
																if(a!=h&&b!=h&&c!=h&&d!=h&&e!=h&&f!=h&&g!=h){
																	for(int i=1;i<10;i++){
																		if(a!=i&&b!=i&&c!=i&&d!=i&&e!=i&&f!=i&&g!=i&&h!=i){
																			if((a+b+c+d==d+e+f+g)&&(a+b+c+d==g+h+i+a)){
																				count++;
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(count/6);
	}
}

【解法二】


全排列

package com.sise.test;

public class Test01 {
	
	public static int count=0;
	
	public static void main(String[] args){
		
		int[] str={1,2,3,4,5,6,7,8,9};
		
		arrange(str,0);
			
		System.out.println(count/6);
	}
	
	public static void arrange(int[] str,int st){
		if(st>=str.length){
			if(check(str)){
				count++;
				return;
			}
		}else{
			for(int i=st;i




你可能感兴趣的:(蓝桥杯)