日期:2014-05-20 浏览次数:20864 次
public static boolean judge(int[] x){ boolean t1 = x[0]==0||x[1]==1; boolean t2 = x[2]==1||x[3]==0; boolean t3 = x[0]+x[2]<=1; boolean t4 = x[1]+x[3]==1; boolean t5 = x[3]+x[4]+x[5]+x[6]+x[7]>=2; boolean t6 = (x[2]+x[6]==0)||(x[2]+x[6]==2); boolean t7 = x[2]+x[4]+x[6]+x[8]<=2; boolean t8 = x[4]==0||(x[5]+x[6]==2); boolean t9 = x[5]==0||(x[6]+x[7]==0); boolean t10 = (x[8]+x[9]>0)||x[7]==1; return t1 && t2 && t3 && t4 && t5 && t6 && t7 && t8 && t9 && t10; }
------解决方案--------------------
for example
char[] c = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; int[] n = new int[c.length]; for (int i=0, t=i; i<(int)Math.pow(2, c.length); i++, t=i) { for (int j=0; j<n.length; j++) { n[n.length-j-1] = t%2; t >>= 1; } boolean check = true; check &= (n[0]==1 ? n[1]==1 : true); //1 check &= (n[2]==0 ? n[3]==0 : true); //2 check &= (n[0]+n[2] <= 1); //3 check &= (n[1]+n[3] == 1); //4 check &= (n[3]+n[4]+n[5]+n[6]+n[7] >= 2); //5 check &= (n[2]==n[6]); //6 check &= (n[2]+n[4]+n[6]+n[8] <= 2); //7 check &= (n[4]==1 ? n[5]==1 && n[6]==1 : true); //8 check &= (n[5]==1 ? n[6]==0 && n[7]==0 : true); //9 check &= (n[8]==0 && n[9]==0 ? n[7]==1 : true); //10 if (check) { for (int j=0; j<n.length; j++) { if (n[j] == 1) { System.out.printf("%c ", c[j]); } } System.out.println(); } }