球盖代码
  • 板块学术版
  • 楼主Pollococido
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/31 19:55
  • 上次更新2025/1/1 00:00:06
查看原帖
球盖代码
919410
Pollococido楼主2024/12/31 19:55
#include <bits/stdc++.h>
using namespace std;
int n, c, s;

struct coin {
    int c, s;
    coin(int a = 0, int b = 0):
        c(a), s(b) {}
};
bool operator <(coin c1,  coin c2) {
    return c1.s > c2.s;
}
priority_queue<coin, vector<coin>, greater<coin> > pq;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> c >> s;
        //st.insert((node){c, s});
        pq.push(coin(c, s));
    }
    while (pq.top().s >= 2) {
        auto p = pq.top();
        pq.pop();

        int tmp = p.s % 2;
        if (!tmp) {
            auto nw = coin(p.s  * p.c, 1);
            pq.push(nw);
        } else {
            auto nw = coin((p.s - 2) * p.c, 1);
            pq.push(nw);
        }
    }
    int ans = 0;
    while (!pq.empty()) {
        cout << pq.top().c << " " << pq.top().s << endl;
        ans += pq.top().s;
        pq.pop();

    }
    cout << ans;
    return 0;
}

为什么 pq.push(coin(c, s)); 会报错,怎么让他不爆错。

错误代码: Clang-Tidy: Constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions

2024/12/31 19:55
加载中...