Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 43381 Accepted Submission(s): 14499
ios
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<iomanip> 5 using namespace std; 6 #define N 1005 7 8 struct Trade{ 9 int J, F; //J表明JavaBeans,F表明cat food 10 double price; //性價比 11 }trade[N]; 12 13 int cmp(Trade a,Trade b) 14 { 15 return a.price>b.price; 16 } 17 int main() 18 { 19 double maximum; 20 int m, n, i; 21 while(cin>>m>>n) 22 { 23 maximum = 0; 24 if(m==-1 && n==-1) 25 break; 26 maximum = 0; 27 for(i=0; i<n; i++) 28 { 29 cin>>trade[i].J>>trade[i].F; 30 trade[i].price = trade[i].J*1.0/trade[i].F; 31 } 32 sort(trade,trade+n,cmp); 33 for(i=0; i<n; i++) 34 { 35 if(m == 0) 36 break; 37 else if(trade[i].F<=m) 38 { 39 maximum += trade[i].J; 40 m -= trade[i].F; 41 } 42 else 43 { 44 maximum += m*trade[i].price; 45 m = 0; 46 } 47 } 48 printf("%.3lf\n",maximum); 49 } 50 return 0; 51 }