跳到正文

题解

题解:P1309 [NOIP2011 普及组] 瑞士轮

GSQ0829约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年1月8日
收录
2026年11月4日
更新
2026年11月18日
篇幅
约 1 分钟
获赞
22
题目
P1309

版本

  1. v1当前

思路:

因为每一轮胜者的得分只加一,所以如果把每一轮的胜败者分别放入两个数组,那么这两个数组就都是有序的,所以我们就可以归并排序合并。在这里我就用了 stable_sort(a, a + n, cmp)。


code:

C++
#include <bits/stdc++.h>
using namespace std;

struct node {
	int d, w, ans;
} a[2000001];

bool cmp(node x, node y) {
	if (x.d != y.d) return x.d > y.d;
	return x.ans < y.ans;
}
int n, r, q;

int main() {
    cin >> n >> r >> q;
    n *= 2;
    for (int i = 0; i < n; i++) {
    	cin >> a[i].d;
    	a[i].ans = i;
    }
    for (int i = 0; i < n; i++) cin >> a[i].w;
    sort(a, a + n, cmp);
    for (int i = 0; i < r; i++) {
    	for (int j = 0; j < n; j += 2) {
    		if (a[j].w > a[j + 1].w) a[j].d++;
    		else a[j + 1].d++;
		}
		stable_sort(a, a + n, cmp);
	}
	cout << a[q - 1].ans + 1;
	return 0;
}
原文
存档评论9 条抓取于