标签:acm
Description
Input
Output
Sample Input
5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1
Sample Output
13.333 31.500#include <iostream> #include <cstring> #include <iomanip> using namespace std; int a[5000],b[5000]; int main() { int t,n,i,j; double c[5000],k,sum; while(cin >> t >> n) { sum=0; if(t==-1&&n==-1) { break; } for(i=0;i<n;i++) { cin >> a[i] >> b[i]; c[i]=a[i]*1.0/b[i]; } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(c[i]<c[j]) { k=c[i]; c[i]=c[j]; c[j]=k; k=b[i]; b[i]=b[j]; b[j]=k; k=a[i]; a[i]=a[j]; a[j]=k; } } } for(i=0;i<n;i++) { if(b[i]<t) { sum+=a[i]; t-=b[i]; c[i]=0; } else { sum+=t*1.0*c[i]; break; } } cout << setiosflags(ios::fixed) << setprecision(3) << sum << endl; } return 0; }
标签:acm
原文地址:http://blog.csdn.net/zsc2014030403015/article/details/43484513