Files
python/TangDou/CSP-J/AcWingTraining/T2/447.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

50 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Node {
int id; // 学生编号
int s; // 总分 score
int p; // 实力
} c[N], a[N], b[N]; // 结果数组,赢者数组,负者数组
bool cmp(Node &a, Node &b) {
if (a.s == b.s) return a.id < b.id;
return a.s > b.s;
}
int main() {
int n, r, q; // 2*n名选手 ,r轮比赛,关心名次q
cin >> n >> r >> q;
n *= 2;
for (int i = 1; i <= n; i++) cin >> c[i].s, c[i].id = i; // 记录每个学生的初始分数,记录学生的id
for (int i = 1; i <= n; i++) cin >> c[i].p; // 记录学生的实力
sort(c + 1, c + n + 1, cmp); // 按初始分数由大到小排序,如果分数一样,那么序号小的在前
while (r--) { // 每一轮比赛
int al = 1, bl = 1;
for (int i = 2; i <= n; i += 2) {
if (c[i - 1].p > c[i].p) // 实力前面的大,那么前面的赢
// 前面的学生总分+1,前面学生进入a数组,后面学生进入b数组
c[i - 1].s++, a[al++] = c[i - 1], b[bl++] = c[i];
else // 否则后面的赢
// 后面学生分数+1,前面学生进入b数组,后面学生进入a数组
c[i].s++, a[al++] = c[i], b[bl++] = c[i - 1];
}
int i = 1, j = 1, k = 0;
while (i < al && j < bl) { // 扫描两个数组
if (cmp(a[i], b[j]))
c[++k] = a[i++]; // a先进入结果数组c,a中游标走到i
else
c[++k] = b[j++]; // b先进入结果数组c,b中游标走到j
}
// 将最后的遗留数据扫入结果数组
while (i < al) c[++k] = a[i++];
while (j < bl) c[++k] = b[j++];
}
// 输出排名第q位的学生序号
cout << c[q].id << endl;
return 0;
}