zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    java 常用
    面试题目总结
    前端自动化构建工具gulp记录
    js面向对象学习笔记
    sass,compass学习笔记总结
    JS核心知识点:DOMBOMEVENT
    boost atomic
    boost thread
    boost function bind ref
    boost phoenix
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7269104.html
Copyright © 2011-2022 走看看