标签:
[2016-02-04][HDU][1009][FatMouse‘ Trade]
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 1000 + 10; struct room{ int j,f; bool operator < (const room & a)const { return ((double)j / f ) > ((double)a.j / a.f ) ; } }r[maxn]; int main(){ int n,m; while(~scanf("%d%d",&m,&n) &&(n != -1 && m != -1)){ for(int i = 0;i < n;i++){ scanf("%d%d",&r[i].j,&r[i].f); } sort(r,r+n); double res = 0,left = m; for(int i = 0; i < n ;i++){ if(left >= r[i].f){ left -= r[i].f; res += r[i].j; }else { res += (left / r[i].f) * r[i].j; break; } } printf("%.3f\n",res); } return 0; }
[2016-02-04][HDU][1009][FatMouse' Trade]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/5182333.html