[2016-02-04] [HDU] [1009] [Fatmouse ' trade]
Fatmouse ' Trade
| Time Limit: 1000MS |
|
Memory Limit: 32768KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status
Description
Fatmouse prepared M pounds of cat food, ready-to-trade with the cats guarding the warehouse containing he favorite food, JavaBean.
The warehouse has N rooms. The i-th contains j[i] pounds of JavaBeans and requires f[i] pounds of cat food. Fatmouse does not has the to trade for all the JavaBeans in the the the same, instead, he may get j[i]* a% of pounds JavaBeans if he Pays f[i]* a% pounds of cat food. Here A is a real number. Now he's assigning this homework to you:tell him the maximum amount of JavaBeans he can obtain.
Input
The input consists of multiple test cases. Each test case is begins with a line containing the non-negative integers M and N. Then N lines follow, each contains, non-negative integers j[i] and f[i] respectively. The last test case was followed by Two-1 ' s. All integers is not greater than 1000.
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of J Avabeans that Fatmouse can obtain.
Sample Input
5 37 24 35 220 325 1824 1515 10-1-1
Sample Output
13.33331.500
#include <cstdio>#include<algorithm>using namespacestd;Const intMAXN = ++Ten;structroom{intj,f; BOOL operator< (ConstB & A)Const { return((Double) j/f) > ((Double) A.J/A.F); }}R[MAXN];intMain () {intn,m; while(~SCANF ("%d%d", &m,&n) && (n! =-1&& m! =-1)){ for(inti =0; I < n;i++) {scanf ("%d%d",&r[i].j,&r[i].f); } sort (R,r+N); Doubleres =0, left =m; for(inti =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;}
From for notes (Wiz)
[2016-02-04] [HDU] [1009] [Fatmouse ' trade]