POJ 1018 Comunication System

    xiaoxiao2021-03-25  301

    Communication System Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28359 Accepted: 10102

    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 ---------------------------------华丽的分割线------------------------------- 问题描述: 输入N个CASE 每个CASE有M台机器 第I台机器有Mi种选择 分别为Bandwidth  Price 记B为所有选好了的机器的Bandwidth的最小值,P为所有Price之和 求B/P的最大值。 解体思路 一:枚举 首先对所有机器(Bandwidth, Price)按照Bandwidth进行降序快排 每一组机器按Price升序快排 (qsort()函数,在<algorithm>中) 然后对Bandwidth进行枚举,over Code: #include<cstring> #include<stdio.h> #include<algorithm> using namespace std; int i,j,k,t,n,m,len[100],bandmax,pricemin,total,pricesum,pricet; float ans; bool jump,gone=true; struct device{ int band; int price; }group[100][100],tmp,st[10000]; int cmp(const void*a,const void*b){ return ((device*)b)->band - ((device*)a)->band; } int cmpp(const void*a,const void*b){ return ((device*)a)->price-((device*)b)->price; } int main() { int t; scanf("%d",&t); while(t--){ memset(group,-1,sizeof(group)); memset(len,0,sizeof(len)); memset(st,0,sizeof(st)); total=0; ans=0.0; scanf("%d",&n); for(i=0;i<n;i++){ for(scanf("%d",&m),j=0;j<m;len[i]++,j++,total++)scanf("%d%d",&group[i][j].band,&group[i][j].price),st[total]=group[i][j]; qsort(group[i],len[i],sizeof(device),cmpp); } qsort(st,total,sizeof(device),cmp); for(k=0;k<total;k++){ jump=true;//if there do not exist device,jump to next bandmax; gone=false;//if there device do not exist, jump to next bandmax; bandmax=st[k].band; pricesum=0; for(i=0;i<n;i++){ jump=true; pricet=0; for(j=0;j<len[i];j++){ if(group[i][j].band>=bandmax){ pricet=group[i][j].price; jump=false;break; } } if(jump){gone=true;break;} pricesum+=pricet; } if(gone)continue; ans=(ans<(float)bandmax/pricesum?(float)bandmax/pricesum:ans); } printf("%.3f\n",ans); } return 0; } 二、DP 日后补充,感觉没必要
    转载请注明原文地址: https://ju.6miu.com/read-122.html

    最新回复(0)