标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 62898 Accepted Submission(s):
21231
#include <string.h> #include <iostream> #include <algorithm> #include <stdlib.h> #include <stdio.h> using namespace std; struct sa { int a,b; double c; }data[3005]; bool cmp(sa x,sa y) { return x.c>y.c; } int main() { int i,j,m,n; double sum; while (cin>>m>>n&&m!=-1&&n!=-1) { sum=0; for (i=0;i<n;i++) { cin>>data[i].a>>data[i].b; data[i].c=(double)data[i].a/(double)data[i].b; } sort(data,data+n,cmp); //for (i=0;i<n;i++) //cout<<data[i].a<<" "<<data[i].b<<" "<<data[i].c<<endl; for (i=0;i<n;i++) { if (m>=data[i].b) { m-=data[i].b; sum+=data[i].a; } else if (m<data[i].b&&m>0) { sum+=data[i].c*(double)m; m=0; } else break; } printf("%.3lf\n",sum); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Ritchie/p/5425318.html