Uvalive 3971 assembling the computer

Source: Internet
Author: User

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=1972

Http://7xjob4.com1.z0.glb.clouddn.com/df5832a56667ea3317ca9166994f1eb6

Test instructions: For computer accessories, prices and performance, the minimum performance of accessories in the specified total price is the largest.

Idea: Using the dichotomy method to find out the performance, so that the performance of the above accessories can be bought within the specified price, the biggest problem of the minimum value.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= ++5;5 6 intN,b,num;7 Chartypec[ -],namec[ -];8 intprice,quality;9 intFP[MAXN][MAXN],FQ[MAXN][MAXN],M[MAXN];Ten  OneVector <string>TP; A voidTrans () - { -     inti,j,l; the     strings=Typec; -L=tp.size (); -      for(i=0; i<l;i++) -     { +         if(tp[i]==s) -         { +m[i+1]++; Afp[i+1][m[i+1]]=Price ; atfq[i+1][m[i+1]]=quality; -             return; -         } -     } - Tp.push_back (s); -m[l+1]++; infp[l+1][m[l+1]]=Price ; -fq[l+1][m[l+1]]=quality; to } +  - intCheckintqu) the { *     inti,j,sum=0; $      for(i=1; i<=num;i++)Panax Notoginseng     { -         intMi=1000000005; the          for(j=1; j<=m[i];j++) +         { A             if(Fq[i][j]>=qu && fp[i][j]<mi) theMi=Fp[i][j]; +         } -         if(mi==1000000005) $             return 0; $sum+=mi; -     } -     if(sum<=b) the         return 1; -     ElseWuyi         return 0; the } -  Wu intMain () - { About     intT; $     inti,j; -scanf"%d",&T); -      while(t--) -     { Ascanf"%d%d",&n,&b); +  theMemset (M,0,sizeof(m)); - tp.clear (); $          for(i=1; i<=n;i++) the         { thescanf"%s%s%d%d",typec,namec,&price,&quality); the trans (); the         } -num=tp.size (); in  the         intL=0, r=1000000005; the          while(L +1<R) About         { the             intMid= (L+R)/2; the             if(check (mid)) the             { +L=mid; -             } the             ElseBayi             { theR=mid; the             } -         } -  theprintf"%d\n", L); the     } the     return 0; the}
View Code

Uvalive 3971 assembling the computer

Related Article

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.