Main topic: To Buy n parts, each part can be supplied by m manufacturers, each part has corresponding B value and P value. (only one can be bought per part) now ask you to find the largest min (b)/sum (p)
Min (b) represents the minimum B value for each part
SUM (p) represents the P-value of each part and
Problem-solving ideas: direct violence
#include <cstdio>#include <algorithm>#include <cstring>using namespace STD;#define MAXNstructdevice{intb, p;} D[MAXN][MAXN];intNUM[MAXN];intNintcmpConstDevice A,ConstDevice b) {returnA.P < B.P;}voidSolve () {scanf("%d", &n); for(inti =0; I < n; i++) {scanf("%d", &num[i]); for(intj =0; J < Num[i]; J + +)scanf("%d%d", &d[i][j].b, &D[I][J].P); Sort (&d[i][0], &d[i][0] + num[i], CMP); }DoubleAns =0.0; for(inti =0; I < n; i++) for(intj =0; J < Num[i]; J + +) {intMin_b = d[i][j].b;intsum_p = D[I][J].P;intK for(k =0; K < n; k++) {if(k = = i)Continue;intTMP =0; while(TMP < NUM[K] && d[k][tmp].b < min_b) tmp++;if(tmp >= Num[k]) Break; Sum_p + = D[K][TMP].P; }if(k >= N && (Double) Min_b/(Double) sum_p > ans) ans = (Double) Min_b/(Double) sum_p; }printf("%0.3f\n", ans);}intMain () {intTestscanf("%d", &test); while(test--) {Solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ-1018 Communication System (violence)