#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