太好了,是lower_bound,我活了
2025-08-30 17:34:34
发布于:广东
8阅读
0回复
0点赞
666也是用上高科技(指lower_bound函数)了
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
string result = "";
vector<int> scores;
for (int i = 0; i < n; ++i) {
int score;
cin >> score;
// 使用 lower_bound 找到插入位置并插入,以保持升序😈😈😈
auto it = lower_bound(scores.begin(), scores.end(), score);
scores.insert(it, score);
int p = i + 1;
int k = floor(p * w / 100.0);
k = max(1, k);
// 第 k 大的元素在升序数组中对应的是 scores[p - k]🤤
int current_score = scores[p - k];
result += to_string(current_score);
if (i != n - 1) {
result += " ";
}
}
cout << result << endl;
return 0;
}
这里空空如也
有帮助,赞一个