文章
49
粉丝
90
获赞
9
访问
29.4k
#include<algorithm>
#include<iomanip>
#include <ios>
#include<iostream>
#include<vector>
using namespace std;
struct drink
{
float m;
float w;
float good;
};
bool compare(drink a, drink b)
{
return a.good > b.good;
}
int main()
{
int x, n;
while (cin >> x >> n)
{
if (x == -1 && n == -1)
return 0;
float sum = 0;
vector<drink> d(n + 1);
{
for (int i = 0; i < n; i++)
{
cin >> d[i].m >> d[i].w;
d[i].good = d[i].m / d[i].w;
}
}
sort(d.begin(), d.end(), compare);
int i = 0;
for (; i < n; i++)
{
if (x > d[i].w)
{
x -= d[i].w;
sum += d[i].m;
}
else
{
break;
}
}
if (i < n)
sum += d[i].m * x / d[i].w;
cout << fixed << setprecision(3) << sum << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发