Communications systems we have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we is free to choose from several manufacturers. Same devices from the 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 T Otal Price (P) was the sum of the prices of all chosen devices. Our goal are 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 is starts with a line containing a single integer n (1≤n≤100) and 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 O F manufacturers for the i-th device, followed by mi pairs of positive integers on the same line, each indicating the BANDW Idth 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 Possib Le b/p for the test case. Round the numbers in the output to 3 digits after decimal point.
Sample Input
1 33 100 25 150 35 80 252 120 80 155 402 100 100 120 110
Test instructions: The system needs n pieces of equipment, each piece of equipment can be produced by m manufacturers, but the width of the price will be different, now each device needs one,
Test instructions required to be satisfied (B/P) Max the case of selecting this N-piece device,
b for the minimum width of the N-piece device, p for the cost
We are in this all set to be small to the width of the large enumeration device, to find out its corresponding minimum price, the last district largest q/p;
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <queue>7#include <map>8#include <Set>9#include <vector>Ten#include <cstdlib> One#include <string> A #defineEPS 0.000000001 -typedefLong Longll; -typedef unsignedLong LongLL; the using namespacestd; - Const intn= -+Ten; - DoubleMax (DoubleADoubleb) { - returnA>b?a:b; + } - intB[n][n],p[n][n]; + intA[n]; A intFintTintN) { at for(intI=1; i<=n;i++) - for(intj=1; j<=a[i];j++) - if(b[i][j]==t)return 1; - return 0; - } - intMain () { in intT,n; - toscanf"%d",&t); + while(t--){ - intminn=0x3f3f3f3f; the intmaxx=-0x3f3f3f3f; *scanf"%d",&n); $ for(intI=1; i<=n;i++){Panax Notoginsengscanf"%d",&a[i]); - for(intj=1; j<=a[i];j++) {scanf ("%d%d",&b[i][j],&p[i][j]); theminn=min (b[i][j],minn); +maxx=Max (B[i][j],maxx); A } the } + //cout<<minn<< "" <<maxx<<endl; - Doubleans=0.0; $ for(inti=minn;i<=maxx;i++){ $ if(f (i,n) = =0)Continue; - intsum=0; - for(intj=1; j<=n;j++){ the intt=0x3f3f3f3f; - for(intk=1; k<=a[j];k++){Wuyi if(b[j][k]>=i) t=min (t,p[j][k]); the } -sum=sum+T; Wu } - //cout<<i<< "" <<sum<<endl; AboutAns=max (ans, (Double) i/sum); $ } -printf"%.3f\n", ans); - } -}
POJ 1018 (enumeration + greedy)