//============================================================================
// Name : 1018.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <algorithm>
#include <cstring>
#define N 100
#define M 100
using namespace std;
int n;
int m[N];
typedef struct device {
int b;
int p;
} Device;
int com(const Device& a, const Device& b) {
if (a.b != b.b) {
return a.b > b.b;
} else {
return a.p > b.p;
}
}
Device d[N][M];
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int max_b = 0;
int min_b = 1 << 20;
for (int i = 0; i < n; i++) {
scanf("%d", &m[i]);
for (int j = 0; j < m[i]; j++) {
scanf("%d %d", &d[i][j].b, &d[i][j].p);
max_b = max(d[i][j].b, max_b);
min_b = min(d[i][j].b, min_b);
}
}
int bbound = max_b - min_b + 1;
int sump[n][bbound];
int ok[n][bbound];
memset(sump, 0, sizeof(sump));
memset(ok, 0, sizeof(ok));
for (int i = 0; i < n; i++) {
sort(d[i], d[i] + m[i], com);
for (int j = 0; j < m[i]; j++) {
sump[i][d[i][j].b - min_b] = d[i][j].p;
ok[i][d[i][j].b - min_b] = 1;
}
for (int j = bbound - 2; j >= 0; j--) {
if (ok[i][j] && ok[i][j + 1]) {
sump[i][j] = min(sump[i][j], sump[i][j + 1]);
} else if (ok[i][j + 1]) {
ok[i][j] = 1;
sump[i][j] = sump[i][j + 1];
}
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < bbound; j++) {
if (ok[i][j]) {
if (ok[i - 1][j]) {
sump[i][j] += sump[i - 1][j];
} else {
ok[i][j] = 0;
}
} else {
break;
}
}
}
int* sum = sump[n - 1];
double max_result = 0;
for (int j = 0; j < bbound && ok[n - 1][j]; j++) {
double result = (j + min_b) / (double) (sum[j] );
max_result = max(max_result, result);
}
printf("%.3f\n", max_result);
}
return 0;
}
poj1018
最新推荐文章于 2018-07-31 15:39:01 发布