求解
2024-09-14 21:01:29
发布于:广东
42阅读
0回复
0点赞
代码:
#include <bits/stdc++.h>
using namespace std;
int p, t;
bool cmp(pair<int, int> t1, pair<int, int> t2) {
if (t1.first < p && t2.first < p)
return t1.first > t2.first;
if (t2.first < p) return 1;
if (t1.first < p) return 0;
if (abs(t2.second - t) > 45) return 1;
if (abs(t1.second - t) > 45) return 0;
return t1.second < t2.second;
}
int main() {
int n, sum = 0;
cin >> n;
vector<pair<int, int>> a;
for (int i = 1; i <= n; i ++) {
for (auto [x, y] : a)
cout << x << " " << y << " ";
cout << endl;
bool h;
cin >> h >> p >> t;
if (!h) {
sum += p;
a.push_back({p, t});
continue;
}
if (a.empty()) {
sum += p;
continue;
}
sort(a.begin(), a.end(), cmp);
if (a.front().first < p || abs(a.front().second - t) > 45)
sum += p;
else {
int tt = a.front().second;
a.pop_back();
}
}
cout << sum;
return 0;
}
这里空空如也
有帮助,赞一个