You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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() {
// 加快读入
ios::sync_with_stdio(false), cin.tie(0);
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;
}