解题思路:全排列 判断条件是否满足
注意事项:
参考代码:
public class llq1{
public static void main(String[] args) {
int []A= {1,2,3,4,5,6,7,8,9};
dfs(A,0);
}
private static void dfs(int[] a, int step) {
// TODO Auto-generated method stub
if(step==a.length) {
if(check(a))
System.out.println(a[0]*100+a[1]*10+a[2]+" "+(a[3]*100+a[4]*10+a[5])+" "+(a[6]*100+a[7]*10+a[8]));
}
else {
for(int i=step;i<a.length;i++) {
swap(a,i,step);
dfs(a,step+1);
swap(a,i,step);
}
}
}
private static void swap(int[] a, int i, int step) {
// TODO Auto-generated method stub
int temp=a[i];
a[i]=a[step];
a[step]=temp;
}
private static boolean check(int[] a) {
// TODO Auto-generated method stub
int a1=a[0]*100+a[1]*10+a[2];
int a2=a[3]*100+a[4]*10+a[5];
int a3=a[6]*100+a[7]*10+a[8];
if(6*a1==3*a2&&3*a2==2*a3)
return true;
else
return false;
}
}
0.0分
0 人评分
格式错误一万年,,有没有过了的来看看(终于过了)浏览:919 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:594 |
简单的a+b (C语言代码)浏览:726 |
简单的a+b (C语言代码)浏览:717 |
【亲和数】 (C语言代码)浏览:495 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:624 |
A+B for Input-Output Practice (II) (C语言代码)浏览:999 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1099 |
【偶数求和】 (C语言代码)浏览:557 |
WU-链表数据求和操作 (C++代码)浏览:1316 |