zoukankan      html  css  js  c++  java
  • POJ1018 Communication System

     
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 26738   Accepted: 9546

    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
     
    动规。f[已处理组数][最大带宽]=价值
     1 /**/
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<algorithm>
     7 using namespace std;
     8 const int INF=1e8;
     9 const int mxn=200;
    10 double ans=0;
    11 int f[mxn][2400];
    12 int b,p;
    13 int n,m;
    14 int main(){
    15     int T;
    16     scanf("%d",&T);
    17     while(T--){
    18         scanf("%d",&n);
    19         memset(f,32,sizeof f);
    20         int i,j;
    21         for(i=1;i<2400;i++)f[0][i]=0;;
    22         for(i=1;i<=n;i++){
    23             scanf("%d",&m);
    24             for(j=1;j<=m;j++){
    25                 scanf("%d%d",&b,&p);
    26                 if(i==1)f[1][b]=min(f[1][b],p);
    27                 else{
    28                     for(int k=0;k<2400;k++)
    29                         f[i][min(k,b)]=min(f[i][min(k,b)],f[i-1][k]+p);
    30                 }
    31             }
    32         }
    33         ans=0;
    34         for(i=1;i<2400;i++){
    35             ans=max(ans,i/(double)f[n][i]);
    36         }
    37         printf("%.3lf
    ",ans);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    利用 PHP 导出 Git 某个分支下,新增或修改过的文件
    [翻译] 10 个实用的 Git 高级命令
    Django web project
    install virtualenv
    js原型继承
    HTML 学习杂记
    IDEA 文件列表隐藏某后缀文件
    coocsCreator杂记
    mac install brew
    c编程:输入一个数字n,则n代表n行,每行输入2个数字a,b计算每行的a+b问题。
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5708679.html
Copyright © 2011-2022 走看看