Fatmouse ' Trade
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 63732 Accepted Submission (s): 21565
Problem Descriptionfatmouse 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.
Inputthe 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.
Outputfor each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum Amoun T of JavaBeans that Fatmouse can obtain.
Sample INPUT5 37 24 35 220 325 1824 1515 10-1-1
Sample Output13.33331.500
Authorchen, Yue
SourceZJCPC2004
#include <iostream>#include<stdio.h>#include<algorithm>using namespacestd;structnode{Doublef,j; DoubleWei;} room[100005];BOOLCMP (Node A,node b) {returnA.wei>B.wei;}intMain () {Doublem; intN; while(SCANF ("%lf%d", &m,&n) && (m!=-1&&n!=-1)) { for(intI=0; i<n;i++) {scanf ("%LF%LF",&room[i].j,&room[i].f); Room[i].wei=room[i].j/room[i].f; } sort (Room,room+n,cmp); Doubleans=0; for(intI=0; i<n;i++) { if(m<=0) Break; if(M>=ROOM[I].F) {m-=room[i].f;ans+=ROOM[I].J;} Else if(M<ROOM[I].F) {ans+=m*room[i].wei;m-=m; Break;} } printf ("%.3lf\n", ans); }}
View Code
Simple greed, nothing to say.
HDU 1009 Fatmouse ' Trade