Fatmouse 'trade
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 15808 accepted submission (s): 4746
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, Yue # Include <iostream> <br/> # include <algorithm> <br/> using namespace STD; <br/> struct fat {// define struct <br/> int X, y; <br/> Double K; <br/>} p [1001]; <br/> bool CMP (fat A, fat B) {<br/> return. k> B. k; <br/>}< br/> int main () {<br/> int I, j, M, N; <br/> while (CIN> m> n, m + n> = 0) {<br/> for (I = 0; I <n; I ++) {<br/> CIN> P [I]. x> P [I]. y; <br/> P [I]. k = P [I]. x * 1.0/P [I]. y; <br/>}< br/> sort (p, p + N, CMP); // sort <br/> double sum = 0, TOT = 0; <br/> for (I = 0; I <n; I ++) {<br/> sum + = P [I]. x; <br/> tot + = P [I]. y; <br/> If (TOT = m) <br/> break; <br/> If (TOT> m) {<br/> tot-= P [I]. y; <br/> sum-= P [I]. x; <br/> sum + = (m-tot) * 1.0/P [I]. y) * P [I]. x); <br/> break; <br/>}< br/> printf ("%. 3lf/N ", sum); <br/>}< br/> return 0; <br/>}