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