Swiss-system tournament

Problem Description

A Swiss-system tournament is a tournament which uses a non-elimination format. The first tournament of this type was a chess tournament in Zurich in 1895, hence the name "Swiss system". The tournament will be held based on following rules.

    2*N contestants (indexed 1, 2, ..., 2*N) will have R rounds matches. Before the first round, every contestant has an origin score. After every match, winner will get 1 score and loser will get 0 score. Before and after every round, contestants will be sorted by their scores in descending order. Two contestants with the same score will be sorted by their index with ascending order.

    In every round, contestants will have match based on the sorted list. The first place versus the second place, the third place versus the forth place, ..., the Kth place versus the (K + 1)th place, ..., the (2*N - 1)th place versus (2*N)th place.

   Now given the origin score and the ability of every contestant, we want to know the index of the Qth place contestant. We ensured that there won’t be two contestants with the same ability and the contestant with higher ability will always win the match.

Input

 Multiple test cases. The first line contains a positive integer T (T<=10) indicating the number of test cases.

For each test case, the first line contains three positive integers N (N <= 100,000), R (R <= 50), Q (Q <= 2*N), separated by space.

The second line contains 2*N non-negative integers, s1, s2, ..., s2*N, si (si<= 108) indicates the origin score of constant indexed i.

The third line contains 2*N positive integers, a1, a2, ..., a2*N, ai (ai<= 108) indicates the ability of constant indexed i.

Output

 One line per case, an integer indicates the index of the Qth place contestant after R round matches.

 

Sample Input

1
2 4 2
7 6 6 7
10 5 20 15

Sample Output

1

Hint

 

 

Versus

Scores after round

Index

/

①(10)

②(5)

③(20)

④(15)

Origin

/

7

6

6

7

Round 1

① VS ④ ② VS ③

7

6

7

8

Round 2

④ VS ① ③ VS ②

7

6

8

9

Round 3

④ VS ③ ① VS ②

8

6

9

9

Round 4

③ VS ④ ① VS ②

9

6

10

9

Source

“浪潮杯”山东省第七届ACM大学生程序设计竞赛

题目简述:

给出2N个选手,每一个人都有初始分数,能力(各不相同)和相应序号,首先根据分数进行排序,分数高的在前面;分数相同,编号小的在前面。然后进行R场比赛,每场比赛在相邻两位选手之间进行(1和2,2和3……)能力值高的获胜,赢的得1分,输的得0分。每场比赛后根据分数按升序列排序。问R场比赛后排名Q的选手的序号是多少。

简略解析:

起始操作的数列是有序的,每一轮比赛后,只看赢的或输的选手,也是有序的。所以每轮比赛后的排序,选择归并法进行操作。

#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int maxn = 100000+10;
struct node{
    int sore;
    int abi;
    int index;
    bool operator <(const node & n)const{
        if(sore == n.sore)
            return index < n .index;
        else
            return sore > n.sore;
    }
};
node a[maxn*2],b[maxn],c[maxn];

void match(int n){
    int num1 = 0,num2 = 0;
    for(int i = 0;i < n;i += 2){
        if(a[i].abi > a[i+1].abi){
            b[num1] = a[i];
            b[num1].sore++;
            num1++;
            c[num2++] = a[i+1];
        }
        else{
            b[num1] = a[i+1];
            b[num1].sore++;
            num1++;
            c[num2++] = a[i];
        }
    }
     int num = 0;
    int i = 0 ,j = 0;
    while(i<num1&&j<num2)
    {
        if(b[i].sore>c[j].sore || (b[i].sore == c[j].sore && b[i].index<c[j].index))
            a[num++] = b[i++];
        else a[num++] = c[j++];
    }

    while(i<num1)
        a[num++] = b[i++];
    while(j<num2)
        a[num++] = c[j++];

}

int main()
{
    int T;
    int N,R,Q;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&N,&R,&Q);
        N = 2*N;
        for(int i = 0;i < N ;i++){
            scanf("%d",&a[i].sore);
            a[i].index = i+1;
        }
        for(int i= 0;i < N;i++){
            scanf("%d",&a[i].abi);
        }
        sort(a,a+N);
        while(R--)
            match(N);
        printf("%d\n",a[Q-1].index);
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值