Sicily 4838. 瑞士轮

4838. 瑞士轮

Constraints

Time Limit: 3 secs, Memory Limit: 256 MB

Description

【背景】
在双人对决的竞技性比赛,如乒乓球、羽毛球、国际象棋中,最常见的赛制是淘汰赛和循环赛。前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高。后者的特点是较为公平,偶然性较低,但比赛过程往往十分冗长。
本题中介绍的瑞士轮赛制,因最早使用于 1895 年在瑞士举办的国际象棋比赛而得名。它可以看作是淘汰赛与循环赛的折衷,既保证了比赛的稳定性,又能使赛程不至于过长。


【问题描述】
2*N 名编号为1~2N 的选手共进行R 轮比赛。每轮比赛开始前,以及所有比赛结束后,都会按照总分从高到低对选手进行一次排名。选手的总分为第一轮开始前的初始分数加上已参加过的所有比赛的得分和。总分相同的,约定编号较小的选手排名靠前。
每轮比赛的对阵安排与该轮比赛开始前的排名有关:第 1 名和第2 名、第3 名和第4名、……、第2K – 1 名和第2K 名、…… 、第 2N – 1 名和第2N 名,各进行一场比赛。每场比赛胜者得1 分,负者得0 分。也就是说除了首轮以外,其它轮比赛的安排均不能事先确定,而是要取决于选手在之前比赛中的表现。
现给定每个选手的初始分数及其实力值,试计算在 R 轮比赛过后,排名第Q 的选手编号是多少。我们假设选手的实力值两两不同,且每场比赛中实力值较高的总能获胜。

Input

输入的第一行是三个正整数 N、R、Q,每两个数之间用一个空格隔开,表示有2*N 名选手、R 轮比赛,以及我们关心的名次Q。
第二行是 2*N 个非负整数s1, s2, …, s2N,每两个数之间用一个空格隔开,其中si 表示编号为i 的选手的初始分数。
第三行是 2*N 个正整数w1, w2, …, w2N,每两个数之间用一个空格隔开,其中wi 表示编号为i 的选手的实力值。

1 ≤ N≤ 100,000,1 ≤ R≤ 50,1 ≤ Q≤ 2N,0 ≤ s1, s2, …, s2N ≤ 10^8,1 ≤ w1, w2, …, w2N ≤ 10^8。

Output

输出只有一行,包含一个整数,即 R 轮比赛结束后,排名第Q 的选手的编号。

Sample Input

2 4 2
7 6 6 7
10 5 20 15

Sample Output

1

Hint

【输入输出样例说明】
本轮对阵 本轮结束后的得分
选手编号 / ① ② ③ ④
初始 /  7 6 6 7
第1 轮①—④ ②—③ 7 6 7 8
第2 轮④—① ③—② 7 6 8 9
第3 轮④—③ ①—② 8 6 9 9
第4 轮③—④ ①—② 9 6 10 9

Problem Source

2012年中山大学每周一赛第二场

// Problem#: 4838
// Submission#: 3533269
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include 
#include 
using namespace std;

const int MAX_N = 200005;

struct man {
    int score, strength, num;
}M[2][MAX_N];

bool cmp(const man & m1, const man & m2) {
    if (m1.score != m2.score) return m1.score > m2.score;
    else return m1.num < m2.num;
}

int winnerPos[MAX_N / 2], loserPos[MAX_N / 2];
char text[2000000];

int main() {

    //std::ios::sync_with_stdio(false);

    int N, R, Q, num;
    scanf("%d%d%d\n", &N, &R, &Q);

    gets(text);  // if there is a lot of data in a line, gets() and then process is faster than scanf()
    int sum = 0;
    int counter = 1;
    for (int i = 0; text[i] != '\0'; i++)
        if (text[i] == ' ') {
            M[0][counter++].score = sum;
            sum = 0;
        } else sum = sum * 10 + text[i] - '0';
    M[0][counter++].score = sum;
    gets(text);
    sum = 0;
    counter = 1;
    for (int i = 0; text[i] != '\0'; i++)
        if (text[i] == ' ') {
            M[0][counter++].strength = sum;
            sum = 0;
        } else sum = sum * 10 + text[i] - '0';
    M[0][counter++].strength = sum;

    num = 2 * N;
    for (int i = 1; i <= num; i++) M[0][i].num = i;
    sort(M[0] + 1, M[0] + num + 1, cmp);  // use quicksort just one time

    int now = 0, next = 1;  // change indexs rather than change data in M-array
    while (R--) {
        int winners = 0, losers = 0;  // the numbers of winners and losers
        for (int i = 2; i <= num; i += 2) {
            if (M[now][i].strength > M[now][i - 1].strength) {
                M[now][i].score++;
                winnerPos[winners++] = i;
                loserPos[losers++] = i - 1;
            } else {
                M[now][i - 1].score++;
                winnerPos[winners++] = i - 1;
                loserPos[losers++] = i;
            }
        }
        int i = 0, j = 0, k = 1;
        while (i < winners && j < losers)  // sort in this way
            if (M[now][winnerPos[i]].score > M[now][loserPos[j]].score)
                M[next][k++] = M[now][winnerPos[i++]];
            else if (M[now][winnerPos[i]].score < M[now][loserPos[j]].score)
                M[next][k++] = M[now][loserPos[j++]];
            else
                if (M[now][winnerPos[i]].num < M[now][loserPos[j]].num) M[next][k++] = M[now][winnerPos[i++]];
                else M[next][k++] = M[now][loserPos[j++]];
        while (i < winners) M[next][k++] = M[now][winnerPos[i++]];
        while (j < losers) M[next][k++] = M[now][loserPos[j++]];
        now = 1 - now;
        next = 1 - next;
    }

    printf("%d\n", M[now][Q].num);

    return 0;
}                                 


你可能感兴趣的:(sicily)