谨以此水题作为我贪心的开始,并没有其他的意思……

http://acm.hdu.edu.cn/showproblem.php?pid=1009

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <time.h>
 8 #include <string>
 9 #include <map>
10 #include <stack>
11 #include <vector>
12 #include <set>
13 #include <queue>
14 #define M  10000
15 #define maxn (1000 + 10)
16 #define pi acos(-1.0)
17 using namespace std;
18 struct room
19 {
20     double JavaBeans;
21     double Food;
22     double Average;
23 };
24 room op[maxn];
25 bool cmp(room a,room b)
26 {
27     return a.Average > b.Average;
28 }
29 int main()
30 {
31 //    freopen("in.txt","r",stdin);
32 //    freopen("in.txt","r",stdin);
33     double m,n,sum = 0;
34     while(scanf("%lf%lf",&m,&n) && !(m == -1 && n == -1))
35     {
36         sum = 0;
37         for(int i = 0; i < n; i ++)
38         {
39             scanf("%lf%lf",&op[i].JavaBeans,&op[i].Food);
40             op[i].Average = op[i].JavaBeans / op[i].Food;
41         }
42         sort(op,op + (int)n,cmp);
43         for(int i = 0; i < n; i ++)
44         {
45             if(m > op[i].Food)
46             {
47                 sum = sum + op[i].JavaBeans;
48                 m = m - op[i].Food;
49             }
50             else
51             {
52                 sum = sum + m / op[i].Food * op[i].JavaBeans;
53                 m = 0;
54             }
55         }
56         printf("%.3lf\n",sum);
57     }
58     return 0;
59 }

 

posted @ 2015-11-27 18:50  徒有羡鱼情  阅读(240)  评论(0)    收藏  举报