fatmouse ' Trade
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (J Ava/others)
Problem Description Fatmouse prepared M pounds of cat food, ready to trade with the Cats guarding warehouse 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, him may get j[i]* a% the of pounds of Pays f[i]* a% pounds of cat food. Here's a real number. Now it is assigning it homework to you:tell him the maximum amount of JavaBeans he can obtain.
Input the 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] and j[i] f[i. The last test case was followed by Two-1 ' s. All integers are 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 Amou NT of JavaBeans that Fatmouse can obtain.
Sample Input
5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10-1-1
Sample Output
13.333 31.500
Author CHEN, Yue
Source ZJCPC2004
Recommend jgshining
#include <iostream> #include <cstdio>using namespaceStd; typedef struct {intBnum; intCnum; DoubleFlag; }Kinds; voidBubblesort(Kinds A[],intN) {intI,J;Kinds T; for (I=1;I<N;I+ +) for (J=0;J<N-I;J+ +) if (A[J].Flag<A[J+1].Flag) {T=A[J];A[J]=A[J+1];A[J+1]=T; int main () {intFnum,Rnum;Kinds A[1002]; while (Cin>>Fnum>>Rnum&& (Fnum!=-1&&Rnum!=-1) ) {doubleSum=0; for (intI=0;I<Rnum;I++) {Cin>>A[I].Bnum>>A[I].Cnum;A[I].Flag=A[I].Bnum*1.0/A[I].Cnum; }Bubblesort(A,Rnum); for (I=0;I<Rnum;I++)Good cheap topic, lost a i<rnum, incredibly WA {However, it is too careless, there may be too much food, resulting in all the room beans have been replaced, there are left, naturally will be wrong.if (Fnum>=A[I].Cnum) {Sum=Sum+A[I].Bnum;Fnum=Fnum-A[I].Cnum; } else {Sum=Sum+1.0*Fnum/A[I].Cnum*A[I].Bnum; Break } }Printf("%.3lf\n",Sum); } return0; }/*************************** in this program, the most experienced is the automatic type conversion, this thing is very useful.
int s;
Double sum;
sum=1+1.0*s;//here an automatic conversion 1.0*s for double type. *****************************/