解题思路:全排列+玫举
注意事项:
参考代码:
import java.util.Scanner;
public class 带分数{
static int N,count;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
N=sc.nextInt();
int data[]={1,2,3,4,5,6,7,8,9};
f(data,0);
System.out.println(count);
}
private static void f(int[] n,int a) {
if(a==9){
print(n);
}
for(int i=a;i<n.length;i++){
int temp=n[a];
n[a]=n[i];
n[i]=temp;
f(n,a+1);
temp=n[a];
n[a]=n[i];
n[i]=temp;
}
}
private static void print(int[] n) {
for(int i=1;i<8;i++){
int num=check(n,0,i);
if(num>=N){
continue;
}
for(int j=i+1;j<=8;j++){
int num1=check(n,i,j);
int num2=check(n,j,n.length);
if(num1%num2==0&&num+(num1/num2)==N){
count++;
}
}
}
}
private static int check(int[] n, int start, int end) {
int sum=0;
int data=1;
for(int i=end-1;i>=start;i--){
sum+=n[i]*data;
data*=10;
}
return sum;
}
}
0.0分
0 人评分