POJ-1018 Communication System (violence)

Source: Internet
Author: User

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, &AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.