❤ • 3天前
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q, u, v, t;
cin >> n >> m >> q >> u >> v >> t;
// 三个优先队列分别存储不同批次的蚯蚓
priority_queue<int> q1, q2, q3;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
q1.push(x);
}
vector<int> cut_results; // 存储被切断的蚯蚓长度
int add = 0; // 偏移量,记录应该增加的长度
for (int time = 1; time <= m; time++) {
// 找到当前最长的蚯蚓
int current_max = -1;
if (!q1.empty())
current_max = q1.top() + add;
if (!q2.empty() && q2.top() + add > current_max)
current_max = q2.top() + add;
if (!q3.empty() && q3.top() + add > current_max)
current_max = q3.top() + add;
// 取出最长的蚯蚓
if (!q1.empty() && q1.top() + add == current_max) {
q1.pop();
} else if (!q2.empty() && q2.top() + add == current_max) {
q2.pop();
} else {
q3.pop();
}
// 记录被切断的蚯蚓长度
cut_results.push_back(current_max);
// 切割蚯蚓
int a = (long long)current_max * u / v;
int b = current_max - a;
// 新产生的蚯蚓不增加长度,所以减去当前的偏移量
q2.push(a - add - q);
q3.push(b - add - q);
// 增加偏移量
add += q;
// 每t秒输出一次结果
if (time % t == 0) {
cout << current_max << " ";
}
}
//cout << endl;
// 收集所有蚯蚓并排序
vector<int> all;
while (!q1.empty()) {
all.push_back(q1.top() + add);
q1.pop();
}
while (!q2.empty()) {
all.push_back(q2.top() + add);
q2.pop();
}
while (!q3.empty()) {
all.push_back(q3.top() + add);
q3.pop();
}
sort(all.rbegin(), all.rend()); // 从大到小排序
// 输出第二行结果
for (int i = t - 1; i < all.size(); i += t) {
cout << all[i] << " ";
}
cout << endl; // 第二行结束,即使没有输出也要有空行
return 0;
}
评论:
请先登录,才能进行评论