后四点RE,求大佬调
查看原帖
后四点RE,求大佬调
384866
danuonuo楼主2024/11/20 22:03

大佬们好,萌新遇到一个奇怪的RE,求调 提交记录 https://www.luogu.com.cn/record/190068282

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

using namespace std;

struct money {
    double mass;
    double value;
    double permassvalue;
};

bool cmp(money a, money b) {
    return a.permassvalue >= b.permassvalue;
}

int main() {
    int n, t;
    cin >> n >> t;
    vector<money> moneyinf;
    for (int i = 0; i < n; i++) {
        int mass, value;
        cin >> mass >> value;
        money moneytmp1;
        moneytmp1.mass = mass;
        moneytmp1.value = value;
        moneytmp1.permassvalue = value / mass;
        moneyinf.push_back(moneytmp1);
    }
    sort(moneyinf.begin(), moneyinf.end(), cmp);
    double currentmass = 0, cursor = 0, currentvalue = 0;
    while (currentmass < t && cursor < moneyinf.size()) {
        if (currentmass+moneyinf[cursor].mass <= t) {
            currentvalue += moneyinf[cursor].value;
            currentmass += moneyinf[cursor].mass;
            cursor++;
        }
        else {
            double diffmass = t - currentmass;
            currentvalue += moneyinf[cursor].permassvalue * diffmass;
            break;
        }
    }
    //cout<<setprecision(2)<<currentvalue;
    printf("%.2f", currentvalue);
    return 0;
}
2024/11/20 22:03
加载中...