标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=1010; 6 struct javabean{ 7 int j,f; 8 double v; 9 }value[maxn]; 10 bool cmp(javabean a,javabean b){ 11 return a.v>b.v; 12 } 13 int main() 14 { 15 int m,n; 16 while(scanf("%d%d",&m,&n)){ 17 if(m==-1&&n==-1) break; 18 for(int i=0;i<n;i++){ 19 scanf("%d%d",&value[i].j,&value[i].f); 20 value[i].v=(double)value[i].j/(value[i].f*1.0); 21 } 22 sort(value,value+n,cmp); 23 double sum=0.0; 24 for(int i=0;i<n;i++){ 25 if(m>=value[i].f){ 26 sum+=value[i].j; 27 m-=value[i].f; 28 } 29 else{ 30 sum+=value[i].v*m; 31 break; 32 } 33 } 34 printf("%.3f\n",sum); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/RRirring/p/4711626.html