Los Switzerland Round Valley P1309

Topic background

In the double duel of competitive games, such as table tennis, badminton, chess, the game system is the most common knockout and round robin. The former is characterized by a small number of the playing field, every game exciting, but a higher chance. The latter is characterized by relatively fair, low chance, but the race is often very lengthy.

This problem is described in Swiss round game system, due to the use of the first chess tournament held in Switzerland in 18,951,895 named. It can be seen as a compromise with the knockout round robin, both to ensure the stability of the game, but also make the race will not be too long.

Title Description

2 \ times N2 × N Name No. 1 \ sim 2N1~2N total of R player games. Before the start of each round, and the end of all the games, players will be out to follow a descending rank. The initial player total score is the score before the start of the first round plus has participated in all competitions and scoring. The same score, the agreed number of smaller players ranking.

Against arrange each round with the top of the round began about: The first 11 and second 22, the first 33 and 44, ......, the first 2K - 12K-1 and No. 2K2K name, ......, the first 2N - 12N-1 and No. 2N2N name, each for a game. Each race winner gets 11 points, the loser 00 points. That is in addition to the first round, another round of arrangement can not be determined in advance, but will depend on the performance of players before the game.

Now given the initial value of the score and the strength of each player, calculate R after round, a player ranked No. QQ number is how much. We assume that the value of the player's strength pairwise disjoint, and high strength values ​​in every game always wins.

Input Format

The first three lines are positive integers N, R, QN, R, Q, each separated by a space between the two numbers, expressed 2 \ times N2 × N players, RR round, and we are concerned ranking QQ.

The second row is 2 \ times N2 × N non-negative integers s_1, s_2, ..., s_ {2N} s1, s2, ..., s2N, between every two numbers separated by a space, wherein s_isi that number is the initial score ii players. The third row is 2 \ times N2 × N positive integers w_1, w_2, ..., w_ {2N} w1, w2, ..., w2N, between every two numbers separated by a space, which represents w_iwi No value for the strength of the players ii.

Output Format

An integer that is the end of the RR round, a player ranked No. QQ number.

Sample input and output

Input # 1 copy

2 4 2
7 6 6 7
10 5 20 15

Output # 1 copy

1

Description / Tips

Sample [explain]

[Thinking]

Quick drain analog +

The idea is very simple
enumeration r times, each time a sorting
and comparison of the comparison should 2k and 2k-1
at the same time adding to the large added value, i.e. ++, or +1
so relatively End r times
the output of the q What number is like a

But quick drain is at least three points of time out
so positive solutions merge sort need to write
it quickly displaces O2 optimization can be a card in the past

[Complete code]

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

using namespace std;
const int Max = 200001;
struct node
{
    int hao;
    int tot;
}a[Max];
int s[Max];

bool cmp(const node x,const node y)
{
    if(x.tot > y.tot)return true;
    else
    if(x.tot == y.tot)
    {
        if(x.hao < y.hao)
            return true;
        else
            return false;
    }
    else
        return false;
}

int main()
{
    int n,r,q;
    scanf("%d%d%d",&n,&r,&q);
    int nn = n << 1;
    for(int i = 1;i <= nn;++ i)
        scanf("%d",&a[i].tot);
    for(int i = 1;i <= nn;++ i)
    {
        a[i].hao = i;
        scanf("%d",&s[i]);
    }
    while(r --)
    {
        sort(a + 1,a + nn + 1,cmp);
        for(int i = 1;i <= n;i ++)
        {
            if(s[a[(i << 1) - 1].hao] > s[a[i << 1].hao])
                a[(i << 1) - 1].tot ++;
            else
                a[i << 1].tot ++;
        }
    }
    sort(a + 1,a + nn + 1,cmp);
    cout << a[q].hao << endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/acioi/p/11619196.html