普及练习场 贪心 排队接水
2017-12-15 17:06
169 查看
题目链接
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理
题意理解
这个就是小学奥数题。花时间少的先干事就好了。注意一下接水的时间没有算在里面,因为要求的是等待时间。代码
import java.util.Arrays; import java.util.Scanner; class Person implements Comparable{ int t; int index; @Override public int compareTo(Object o) { Person person = (Person) o; if(person.t != this.t) { return this.t - person.t; } else { return this.index - person.index; } } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); Person[] persons = new Person ; for(int i = 0; i < N; i++) { persons[i] = new Person(); persons[i].t = scanner.nextInt(); persons[i].index = i + 1; } scanner.close(); Arrays.sort(persons); double sum = 0; for(int i = 0; i < N; i++) { System.out.print(persons[i].index + " "); sum += persons[i].t * (N - i - 1); } System.out.println(); System.out.printf("%.2f", sum / N); } }
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理
相关文章推荐
- 普及练习场 贪心 国王游戏
- 普及练习场 贪心 合并果子
- 普及练习场 贪心 数列分段
- 普及练习场 贪心 [USACO1.3]混合牛奶 Mixing Milk
- 普及练习场 贪心 凌乱的yyy
- 普及练习场 贪心 纪念品分组
- 普及练习场 贪心EX 皇后游戏
- 普及练习场 贪心EX 木棍加工
- wikioi-天梯-普及一等-贪心-1098:均分纸牌
- 普及练习场 排序 【模板】快速排序
- 普及练习场 深度优先搜索 加分二叉树
- 普及练习场 广度优先搜索 马的遍历
- 普及练习场 分治算法 取余运算与快速幂
- 普及练习场 更要技巧的动规与记忆化 乌龟棋
- 普及练习场 简单数学 A % B Problem
- 【重走普及路】【贪心】合并果子
- wikioi-天梯-普及一等-贪心-1214:线段覆盖
- 普及练习场 排序 明明的随机数
- 普及练习场 深度优先搜索 八皇后
- 【贪心】洛谷 P1223 排队接水