80分求助!
查看原帖
80分求助!
960665
E_RONALDO楼主2024/3/31 10:37
#include <bits/stdc++.h>
using namespace std;
struct coin{
    int m,value;
    double Average_price;
}a[105];
bool cmp(coin c1, coin c2){
    return c1.Average_price>c2.Average_price;
}
int main()
{
    int n,t,book=0;
    double ans=0;
    cin>>n>>t;
    for(int i=1;i<=n;i++){
        cin>>a[i].m>>a[i].value;
        a[i].Average_price=1.0*a[i].value/a[i].m;
    }
    sort(a+1,a+1+n,cmp);
    while(t>=a[book].m&&book<n){
        t-=a[book].m;
        ans+=a[book].value;
        book++;
    }
    ans+=t*a[book].Average_price;
    printf("%.2f",ans);
    return 0;
}

//80pts

2024/3/31 10:37
加载中...