文章
38
粉丝
11
获赞
2
访问
30.9k
#include<bits/stdc++.h>
using namespace std;
struct Drink{
double mi,wi;//mi毫升,价格为wi
}dk[1010];
bool cmp(Drink a,Drink b){
return a.mi / a.wi > b.mi / b.wi;
}
int main(){
int x,n;
while(cin >> x >> n){
if(x == -1 && n == -1) break;
for(int i = 0;i < n;i++) cin >> dk[i].mi >> dk[i].wi;
sort(dk,dk + n,cmp);
double sum = 0;
int i = 0;
for(i = 0;i < n;i++){
x -= dk[i].wi;
if(x < 0) {
x += dk[i].wi;
sum += (dk[i].mi / dk[i].wi * x);
break;
...
登录后发布评论
暂无评论,来抢沙发