1#include <iostream>2#include <cstdio>3#include <iostream>4 using namespacestd;5 structnode{6 intg,p;7 DoubleAve;8} s[10010];9 Ten intMain () One { A intn,w; - Doublesum=0; -scanf"%d%d",&n,&W); the for(intI=0; i<n;i++) -scanf"%d%d",&s[i].g,&S[I].P); - for(intI=0; i<n;i++) -S[i].ave= (Double) s[i].p/s[i].g; + //for (int i=0;i<n;i++) - //printf ("%d%d%f\n", s[i].g,s[i].p,s[i].ave); + for(intI=0; i<n-1; i++) A { at for(intj=i;j<n;j++) - { - if(s[i].ave<s[j].ave) - { - intt,x; - Doubleav; in - toAv=s[i].ave; S[i].ave=s[j].ave; S[j].ave=av; + - theT=S[I].P; S[I].P=S[J].P; s[j].p=T; * $X=S[I].G; S[I].G=S[J].G; s[j].g=x; Panax Notoginseng - } the } + } A //for (int i=0;i<n;i++) the //printf ("%d%d%f\n", s[i].g,s[i].p,s[i].ave); + inti; - for(i=0; i<n;i++) $ { $ if(w>=s[i].g) - { -sum+=S[I].P; thew-=S[I].G; - }Wuyi Else the Break; - } Wu if(w==0) - ; About Else $ { -sum=sum+ (w*s[i].ave); - } -printf"%.1f\n", sum); A + the}
View Code
Algorithm to improve happy drivers