import java.util.Scanner;
import java.util.Arrays;
import java.text.DecimalFormat;
public class Main {
public static class Band implements Comparable{
final int a;
final int t;
int dv;
public Band(int a, int t) {
this.a = a;
this.t = t;
dv = a * t;
} @Override public int compareTo(Band other) {
return Integer.compare(other.dv, this.dv);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Band[] array = new Band[n + 1];
for (int i = 1; i <= n; i++) {
int a = in.nextInt();
int t = in.nextInt();
array[i] = new Band(a, t);
}
Arrays.sort(array);
long v = 0;
double d = 0;
Arrays.sort(array);
for (Band band : array) {
// System.out.println(band.dv);
d += v * band.t + 0.5 * band.a * band.t* band.t;
v += band.a * band.t;
}
DecimalFormat df = new DecimalFormat("0.0");
System.out.println(df.format(d));
}
}
用例1 运行结果:
说明:测试数据未输出正确结果!
运行时间:148 MS
运行内存:10988 KB
错误信息:
你的输出为:Exception in thread "main" java.lang.NullPointerException
at Main$Band.compareTo(Main.java:18)
at Main$Band.compareTo(Main.java:6)
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
at java.util.Arrays.sort(Arrays.java:1246)
at Main.main(Main.java:32)
代码运行没通过?建议您再仔细阅读编程题须知,现在查看