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
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 using namespacestd;6 intMain ()7 {8 intM,n;9 intf[ -],j[ -];Ten Doublea[ -],b[ -]; One intnext[ +]; A while((scanf ("%d%d", &m,&n) && (m!=-1|| n!=-1))) - { - for(intI=0; i<n;i++) the { -scanf"%d%d",&f[i],&j[i]); -a[i]=1.0*f[i]/J[i]; - } + Doublenum=0; - for(intI=0; i<n;i++) + { A for(intk=i+1; k<n;k++) at { - if(a[i]<A[k]) - { - swap (a[i],a[k]); - swap (f[i],f[k]); - swap (j[i],j[k]); in } - } to if(j[i]<m) + { -num+=F[i]; them-=J[i]; * } $ ElsePanax Notoginseng { - thenum+=1.0*f[i]*m/J[i]; +m=0; A } the if(m==0) + { - Break; $ } $ } -printf"%.3lf\n", num); - } the}View Code
ZSC_ Winter Training 3