标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 67905 Accepted Submission(s): 23150
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> typedef long long ll; using namespace std; struct node { int x,y; double num; }a[10000]; bool cmp(node xx,node yy){ return xx.num>yy.num; } int main(){ int m,n; int i,j; while(scanf("%d%d",&m,&n)!=EOF){ if(m==-1&&n==-1) break; for(i=1;i<=n;i++){ scanf("%d%d",&a[i].x,&a[i].y); a[i].num=(double)a[i].x/a[i].y; } sort(a+1,a+n+1,cmp); double sum=0; for(i=1;i<=n;i++){ //cout<<a[i].num<<endl; if(a[i].y<=m) { sum=sum+a[i].x; m=m-a[i].y; } else{ sum=sum+a[i].num*m; break; } } printf("%.3f\n",sum); } }
标签:
原文地址:http://www.cnblogs.com/Aa1039510121/p/5942836.html