解题思路:
注意事项:
参考代码:
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main10 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int w = scanner.nextInt(); double[][] car=new double[n][2]; for (int i = 0; i < car.length; i++) { car[i][0]=scanner.nextInt(); car[i][1]=scanner.nextInt(); } Arrays.sort(car,new Comparator<double[]>() { public int compare(double[] o1,double[] o2) { return (o1[1]/o1[0])-(o2[1]/o2[0])<0?1:-1; } }); double sum=0; for (int i = 0; i < car.length; i++) { if(car[i][0]<w) { sum+=car[i][1]; w-=car[i][0]; } else { sum+=(car[i][1]/car[i][0])*w; break; } } System.out.printf("%.1f\n", sum); } }
0.0分
1 人评分
众数问题 (C语言代码)浏览:3569 |
点我有惊喜!你懂得!浏览:2114 |
C二级辅导-进制转换 (C语言代码)浏览:551 |
母牛的故事 (C语言代码)浏览:1409 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1914 |
A+B for Input-Output Practice (III) (C语言代码)浏览:592 |
C语言训练-数字母 (C语言代码)浏览:670 |
DNA (C语言描述,数据结构)浏览:909 |
【绝对值排序】 (C语言代码)浏览:892 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:2121 |