概述
http://acm.hdu.edu.cn/showproblem.php?pid=1009
如下写法会导致PE
System.out.format("%.3fn", sum);
import java.awt.image.ImageConsumer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
int M = input.nextInt();
int N = input.nextInt();
if (M == -1 && N == -1) {
return;
}
List<Room> rooms = new ArrayList<>();
double sum = 0;
for (int i = 0; i < N; i++) {
Room room = new Main().new Room(input.nextInt(), input.nextInt());
rooms.add(room);
}
Collections.sort(rooms);
for (Room room : rooms) {
if (M == 0) {
break;
}
if (M >= room.getCatFood()) {
M -= room.getCatFood();
sum += room.getJavaBean();
} else {
sum += M * 1.0 / room.getCatFood() * room.getJavaBean();
M = 0;
}
}
System.out.format("%.3f", sum);
System.out.println();
}
}
class Room implements Comparable<Room> {
private int javaBean;
private int catFood;
private double x;
public Room(int j, int f) {
this.javaBean = j;
this.catFood = f;
this.x = javaBean * 1.0 / catFood;
}
public int getJavaBean() {
return javaBean;
}
public void setJavaBean(int javaBean) {
this.javaBean = javaBean;
}
public int getCatFood() {
return catFood;
}
public void setCatFood(int catFood) {
this.catFood = catFood;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
@Override
public int compareTo(Room o) {
return this.getX() > o.getX() ? -1 : 1;
}
@Override
public String toString() {
return String.format("%s %s %s", this.javaBean, this.catFood, this.x);
}
}
}
最后
以上就是舒服书包为你收集整理的1009 -的全部内容,希望文章能够帮你解决1009 -所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复