暴力解决:
运用枚举的方法从大自小进行枚举,并调用方法判断是否符合每个位数上的数均不同的核心思想解题
package 蓝桥杯练习题目;
public class _17决赛A_优化 {
static long start=90000;
static long end=100000;
static long max=0;
public static boolean pd(long p) {
int arr[]=new int[11];
for(int i=1;i<=10;i++) {
int d=(int) (p%10);
long c=p/10;
if(arr[d]==1) {
return false;
}
else {
arr[d]++;
}
}
return true;
}
public static void mian(String args[]) {
a: for(int i=1;i<=7;i++) {
for(long j=end-1;j>=start;j--) {
if(pd(j*j)) {
max=j*j;
break a;
}
}
end=start;
start=start-10000;
}
System.out.print(max);
}
}