POJ1018
来源:互联网 发布:js for each 编辑:程序博客网 时间:2024/05/17 00:52
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1018
思路:贪心,Bw能取的范围是全部bw中的最小的到每个机器的bw最大值集合中的最小的一个,迭代bw的值,每次取最小的pri的和,求出b/p的最大值。
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Main {
- double bp = 0;
- public Main() throws NumberFormatException, IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(
- System.in));
- int t = Integer.parseInt(read.readLine());
- int num;
- int[][] b;
- int[][] p;
- int[] n;
- int bmin = Integer.MAX_VALUE;
- int[] bmaxs;
- int bmax;
- String[] s;
- int sum;
- int temp;
- for (int i = 0; i < t; i++) {
- num = Integer.parseInt(read.readLine());
- b = new int[num][];
- p = new int[num][];
- n = new int[num];
- bmin = Integer.MAX_VALUE;
- bmaxs = new int[num];
- bmax = Integer.MAX_VALUE;
- for (int j = 0; j < num; j++) {
- s = read.readLine().split(" ");
- n[j] = Integer.parseInt(s[0]);
- b[j] = new int[n[j]];
- p[j] = new int[n[j]];
- for (int k = 0; k < n[j]; k++) {
- b[j][k] = Integer.parseInt(s[k * 2 + 1]);
- if (b[j][k] > bmaxs[j]) {
- bmaxs[j] = b[j][k];
- }
- if (b[j][k] < bmin) {
- bmin = b[j][k];
- }
- p[j][k] = Integer.parseInt(s[k * 2 + 2]);
- }
- }
- for (int j = 0; j < num; j++) {
- if (bmaxs[j] < bmax) {
- bmax = bmaxs[j];
- }
- }
- bp = 0;
- for (int j = bmin; j <= bmax; j++) {
- sum = 0;
- for (int k = 0; k < num; k++) {
- temp = Integer.MAX_VALUE;
- for (int h = 0; h < n[k]; h++) {
- if (b[k][h] >= j && p[k][h] < temp) {
- temp = p[k][h];
- }
- }
- sum += temp;
- }
- if ((double) j / sum > bp) {
- bp = (double) j / sum;
- }
- }
- System.out.printf("%.3f/n", bp);
- }
- }
- public static void main(String[] args) throws NumberFormatException,
- IOException {
- new Main();
- }
- }
- POJ1018
- poj1018
- poj1018
- poj1018
- poj1018
- poj1018
- poj1018
- poj1018
- poj1018
- poj1018
- POJ1018
- poj1018
- poj1018
- poj1018
- poj1018
- POJ1018
- POJ1018
- poj1018
- 轻松玩转CreateRemoteThread,让你的代码长出翅膀
- IE与Firefox的区别
- 还是回这里吧
- CSS hacks
- 2003服务器被入侵,如果还原Gest用户,删除隐藏用户
- POJ1018
- 只有小学文凭就没资格学软件吗?
- [转]asp.net(c#)怎样将图片存入数据库?
- Asp.Net传参方式小结
- 求绝对值的函数模版
- 刻录光盘的方方面面和诀窍
- linkinghub.elsevier.com上的文章也可以直接下
- 如何实现API钩子
- thickbox 如何跨越Iframe