我是靠谱客的博主 舒服书包,这篇文章主要介绍1009 -,现在分享给大家,希望可以做个参考。


http://acm.hdu.edu.cn/showproblem.php?pid=1009

如下写法会导致PE

复制代码
1
System.out.format("%.3fn", sum);


复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部