FatMouse 'tradetime Limit: 2000/1000 ms (Java/Other) Memory Limit: 65536/32768 K (Java/Other) Total Submission (s): 20 Accepted Submission (s): 14 Font: times New Roman | Verdana | GeorgiaFont Size: Regular → Problem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. the I-th room contains J [I] pounds of JavaBeans and requires F [I] pounds of cat food. fatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J [I] * a % pounds of JavaBeans if he pays F [I] * a % pounds of cat food. here a is a real number. now he is 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 begins with a line containing two non-negative integers M and N. then N lines follow, each contains two non-negative integers J [I] and F [I] respectively. the last test case is followed by two-1's. all integers are 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 amount of JavaBeans that FatMouse can obtain.
Sample Input
5 37 24 35 220 325 1824 1515 10-1 -1
Sample Output
13.33331.500
AuthorCHEN and YueSource are simple greedy questions. They are first sorted by the value/price ratio. They must be bought first with a large ratio.
#include
#includeusing namespace std;struct stu{int a;int b;double rate;}s[1005];bool cmp(stu x,stu y){ if(x.rate!=y.rate)return x.rate>y.rate; else return x.a
=s[i].b){m-=s[i].b;cnt+=s[i].a;} else { cnt+=s[i].rate*m;break; }} printf("%.3lf\n",cnt);}return 0;}