蓝桥杯 第七届决赛 七星填数 JAVA

来源:互联网 发布:南京网络问政回复时间 编辑:程序博客网 时间:2024/06/05 06:42
class Main {static int a[] ={1,2,3,4,5,7,8,9,10,12,13};    public static void main(String[] args)  {    int b []= new int[14];    b[0] = 6;    b[8] = 14;    b[10] = 11;    boolean c[] = new boolean[14];    boolean d[] = new boolean[14];    c[0] = true;    c[8] = true;    c[10] = true;        f(b,c,d,0);}private static void f(int[] b, boolean[] c, boolean d[],int i) {if(i==9){if(b[1]+b[2]+b[3]+b[4] != b[0]+b[2]+b[5]+b[8])return;}if(i == 11){if(b[1]+b[2]+b[3]+b[4] != b[0]+b[3]+b[6]+b[10])return;}if(i == 12){if(b[1]+b[2]+b[3]+b[4] != b[1]+b[5]+b[7]+b[11])return;}if(i == 13){if(b[1]+b[2]+b[3]+b[4] != b[9]+b[10]+b[11]+b[12])return;}if(i==b.length){if(b[1]+b[2]+b[3]+b[4] != b[7]+b[8]+b[12]+b[13])return;if(b[1]+b[2]+b[3]+b[4] != b[4]+b[6]+b[9]+b[13])return;for (int j = 0; j < c.length; j++) {System.out.print(b[j]+" ");}System.out.println();return;}if(!c[i]){for (int j = 0; j < a.length; j++) {if(!d[j]){d[j] =true;c[i] = true;b[i] = a[j];f(b,c,d,i+1);d[j] = false;c[i] = false;}}}else{f(b,c,d,i+1);}}}

阅读全文
0 0