分数线题解
2026-04-11 16:30:14
发布于:江苏
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct Candidate {
int id; // 报名号
int score; // 笔试成绩
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<Candidate> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].id >> a[i].score;
}
// 计算面试分数线位置(m*150% 向下取整)
int pos = m * 3 / 2; // 等价于 floor(m * 1.5)
// 按成绩降序,成绩相同按报名号升序排序
sort(a.begin(), a.end(), [](const Candidate& a, const Candidate& b) {
if (a.score != b.score) return a.score > b.score;
return a.id < b.id;
});
// 面试分数线是第 pos 名的分数(1-based,所以是下标 pos-1)
int cutoff = a[pos - 1].score;
// 统计进入面试的人数(成绩 >= 分数线的所有选手)
int count = 0;
for (int i = 0; i < n; i++) {
if (a[i].score >= cutoff) {
count++;
} else {
break; // 因为已按成绩降序,后面的都小于分数线
}
}
// 输出
cout << cutoff << " " << count << "\n";
for (int i = 0; i < count; i++) {
cout << a[i].id << " " << a[i].score << "\n";
}
return 0;
}
这里空空如也



有帮助,赞一个