再贴一版poj1018,其实与之前的那一版差不多,只是去掉了注释,这样可能看起来会舒服一点
package com.njupt.acm;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class TestPOJ1018 {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(reader.readLine());
for(int i = 0 ; i < t ; ++i ){
int num = Integer.parseInt(reader.readLine());
int[][] b = new int[num][];
int[][] p = new int[num][];
int bmax = Integer.MAX_VALUE;
int bmin = Integer.MAX_VALUE;
int[] bmaxs = new int[num];
int[] n = new int[num];
int sum = 0;
double bp = 0;
for( int j = 0 ; j < num ; ++j ){
String[] s = reader.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]);
}
if( bmaxs[j] < bmax){
bmax = bmaxs[j];
}
}
for( int j = bmin ; j <= bmax ;++ j){
sum = 0;
for( int k = 0 ; k < num ; ++k ){
int 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];
}
}
// System.out.println("temp:" + temp);
sum += temp;
// System.out.println("sum:" + sum);
}
if( (double)j/sum > bp){
bp = (double)j/sum;
}
}
// System.out.println(Arrays.toString(bmaxs));
// System.out.println("bmax:" + bmax);
// System.out.println("bmin:" + bmin);
// System.out.println("sum:" + sum);
System.out.printf("%.3f\n", bp);
}
}
}