标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 59851 Accepted Submission(s): 20095
1 #include <cstdio>
2 #include <algorithm>
3 using namespace std;
4
5 const int MAX=1050;
6 struct Room{
7 double j;
8 double f;
9 double w;
10 }r[MAX];
11
12 bool compare(const Room &r1,const Room &r2)
13 {
14 if(r1.w>r2.w)
15 return true;
16 else
17 return false;
18 }
19
20 int main()
21 {
22 double m,ans,jv,fv;
23 int n;
24 while(scanf("%lf%d",&m,&n)==2&&n!=-1)
25 {
26 ans=0;
27 for(int i=0;i<n;i++)
28 {
29 scanf("%lf%lf",&jv,&fv);
30 r[i].j=jv;
31 r[i].f=fv;
32 r[i].w=jv/fv;
33 }
34 sort(r,r+n,compare);
35
36 for(int i=0;i<n;i++)
37 {
38 if(m>=r[i].f)
39 {
40 m-=r[i].f;
41 ans+=r[i].j;
42
43 }
44 else
45 {
46 ans+=r[i].w*m;
47 break;
48 }
49 }
50 printf("%.3lf\n",ans);
51 }
52 }
标签:
原文地址:http://www.cnblogs.com/cumulonimbus/p/5158720.html