标签:
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct laoshu { int j; int f; double s; }; bool cmp(laoshu stud1,laoshu stud2) { return stud1.s>stud2.s; } int main() { #ifdef CDZSC_OFFLINE freopen("in.txt","r",stdin); #endif int i,m,n; double sum; laoshu stud[1010]; while(scanf("%d%d",&m,&n)&&m!=-1&&n!=-1) { sum=0; for(i=0; i<n; i++) { scanf("%d%d",&stud[i].j,&stud[i].f); stud[i].s=1.0*stud[i].j/stud[i].f; } sort(stud,stud+n,cmp); for(i=0; i<n; i++) { if(m>=stud[i].f) { sum+=stud[i].j; m-=stud[i].f; } else { sum+=stud[i].s*m; break; } } printf("%.3lf\n",sum); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Wing0624/p/4243805.html