# POJ 1018 Communication System

Communication System

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 28182

Accepted: 10049

Description

We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices. By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case starts with a line containing a single integer n (1 ≤ n ≤ 100), the number of devices in the communication system, followed by n lines in the following format: the i-th line (1 ≤ i ≤ n) starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th device, followed by mi pairs of positive integers in the same line, each indicating the bandwidth and the price of the device respectively, corresponding to a manufacturer.

Output

Your program should produce a single line for each test case containing a single number which is the maximum possible B/P for the test case. Round the numbers in the output to 3 digits after decimal point.

Sample Input

```1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110```

Sample Output

`0.649`

Source

Tehran 2002, First Iran Nationwide Internet Programming Contest

dp代码：

``` 1 #include <iostream>
2 #include <cstdio>
3 #include <queue>
4 #include <iomanip>
5 using namespace std;
6
7 const int maxn=1100;
8 const int inf=0x3f3f3f3f;
9 int dp[maxn];
10
11 struct node{
12     int flow,sum;
13     node(int flow0=0,int sum0=0){
14         flow=flow0,sum=sum0;
15     }
16 };
17
18 void solve(){
19     queue <node> q;
20     q.push(node(inf,0));
21     int n,m,flow,price;
22     scanf("%d",&n);
23     for(int i=1;i<=n;i++){
24         scanf("%d",&m);
25         for(int i=0;i<maxn;i++) dp[i]=inf;
26         while(m-- >0){
27             scanf("%d%d",&flow,&price);
28             int qsize=q.size();
29             while(qsize-- >0){
30                 node s=q.front();
31                 q.pop();
32                 if(s.flow<flow){
33                     if(s.sum+price<dp[s.flow]) dp[s.flow]=s.sum+price;
34                 }else{
35                     if(s.sum+price<dp[flow]) dp[flow]=s.sum+price;
36                 }
37                 q.push(s);
38             }
39         }
40         while(!q.empty()) q.pop();
41         for(int i=0;i<maxn;i++){
42             if(dp[i]<inf) q.push(node(i,dp[i]));
43         }
44     }
45     double ans=0;
46     while(!q.empty()){
47         node s=q.front();
48         q.pop();
49         if(double(s.flow)/double(s.sum) > ans) ans= double(s.flow)/double(s.sum) ;
50     }
51     cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
52 }
53
54 int main(){
55     int t;
56     scanf("%d",&t);
57     while(t-- >0){
58         solve();
59     }
60     return 0;
61 }```

781 篇文章62 人订阅

0 条评论

## 相关文章

1733

5537

2303

632

1613

### 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MB ...

2585

42811

1213

1640

4675