Fatmouse 'trade
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 32207 accepted submission (s): 10402
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
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, Yue
Sourcezjcpc2004
Recommendjgshining greedy sort by swap ratio. It starts from the exchange ratio.
# include
# include
# include
using namespace STD; struct Jud {Double J, F, JF;} JD [1010]; int CMP (Jud A, Jud B) {return. jf> B. jf;} int main () {int n, m, I; double MA; while (scanf ("% d", & M, & n )) {If (n =-1 & M =-1) break; for (I = 0; I
JD [I]. f) MA + = JD [I]. j, M-= JD [I]. f; else {MA + = m * JD [I]. jf; break;} printf ("%. 3lf \ n ", Ma) ;}return 0 ;}