#阿里笔试2020#
阿里4.15笔试第二题
同样用的暴力,但是是0,求解答我的暴力哪里错了
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n=sc.nextLong();
long[] A=new long[Math.toIntExact(n)];
long[] B= new long[Math.toIntExact(n)];
for(long i=0;i<Math.toIntExact(n);i++){
Scanner sc1 = new Scanner(System.in);
A[Math.toIntExact(i)]=sc1.nextLong();
B[Math.toIntExact(i)]=sc1.nextLong();
}
double min=0;
double max=0;
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
min=Math.min((A[Math.toIntExact(i)]+A[Math.toIntExact(j)])/2.0,(B[Math.toIntExact(i)]+B[Math.toIntExact(j)])/2.0);
max=Math.max(max,min);
}
}
System.out.print(max);
}
}
阿里4.15笔试第二题
同样用的暴力,但是是0,求解答我的暴力哪里错了
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n=sc.nextLong();
long[] A=new long[Math.toIntExact(n)];
long[] B= new long[Math.toIntExact(n)];
for(long i=0;i<Math.toIntExact(n);i++){
Scanner sc1 = new Scanner(System.in);
A[Math.toIntExact(i)]=sc1.nextLong();
B[Math.toIntExact(i)]=sc1.nextLong();
}
double min=0;
double max=0;
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
min=Math.min((A[Math.toIntExact(i)]+A[Math.toIntExact(j)])/2.0,(B[Math.toIntExact(i)]+B[Math.toIntExact(j)])/2.0);
max=Math.max(max,min);
}
}
System.out.print(max);
}
}
全部评论
相关推荐
今天 13:46
门头沟学院 硬件开发 点赞 评论 收藏
分享
点赞 评论 收藏
分享

点赞 评论 收藏
分享