• POJ 1018 Communication System


    Communication System
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 29206   Accepted: 10401

    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

    枚举+贪心
    #include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath> 
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 0x3f3f3f3f3f 
    #define mem(a) (memset(a,0,sizeof(a))) 
    typedef long long ll;
    vector<pair<int,int> >v[105];
    int n,pos,t,x,y,m;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            for(int i=0;i<102;i++) 
                v[i].clear();
            scanf("%d",&n);
            for(int i=0;i<n;i++)
            {
                scanf("%d",&m);
                for(int j=0;j<m;j++)
                {
                    scanf("%d%d",&x,&y);
                    v[i].push_back(make_pair(x,y));
                }
            }
            double maxn=0.0;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<v[i].size();j++)
                {
                    double l=v[i][j].second,r=v[i][j].first;
                    for(int k=0;k<n;k++)
                    {
                        if(k==i) continue;
                        pos=99999999;
                        for(int z=0;z<v[k].size();z++)
                        {
                            if(v[k][z].first<v[i][j].first) continue;
                            if(pos>v[k][z].second) pos=v[k][z].second;
                        }
                        if(pos==99999999) break;
                        l+=pos;
                    }
                    if(pos==99999999) break;
                    if(maxn<(r/l)) maxn=(r/l);
                }
            }
            printf("%.3f
    ",maxn);
        }
        return 0;
    }
  • 相关阅读:
    【掉下巴】枪的制造现场
    不引入第三个变量交换两个变量的方法
    [转]科学计算经典算法
    [小练eVC]常用控件之微调按钮
    【收购】LSI 40亿美元并购Agere
    VB6.0不支持鼠标滚轮的解决办法
    一个简单的BP网络C语言程序
    [转]想成为嵌入式程序员应知道的0x10个基本问题
    [zt]关于左值"lvalue"和右值"rvalue"的一点理解
    [掉下巴]细数非洲大山的肘下亡魂
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7269104.html
Copyright © 2020-2023  润新知