NOIP 2011 Swiss Wheel

Source: Internet
Author: User
Tags sort

Topic background

In competitive competitions such as table tennis, badminton and chess, the most common format is knockout and round robin. The former is characterized by less than the number of games, each with a tense stimulus, but the contingency is higher. The latter is characterized by fairness and low contingency, but the course of the competition is often lengthy.

The Swiss round format, introduced in the subject, was named after the earliest use of the chess competition held in Switzerland in 1895. It can be seen as a compromise between the knockout and the round robin, both to ensure the stability of the game and to keep the fixtures from being too long.
Title Description

2*n, a player named 1~2n, has a total R-wheel race. Players will be ranked from highest to lowest in each round before the start of the game and after all competitions have been completed. The total score for the player is the initial fraction before the start of the first round plus the scores of all the matches that have been played. With the same total score, the players with the smaller number of contracts are ranked front.

The match arrangement for each round is related to the ranking before the start of the competition: 1th and 2nd, 3rd and 4th 、......、 2k–1 and 2nd k 、...... 、 2n–1 and 2N, each with a match. Each match wins 1 points, the negative 0 points. In other words, other than the first round, the arrangement of the other rounds is not predetermined, but depends on the player's performance in the previous match.

Given the initial score of each player and their strength, try to calculate the number of players in Q after the R-round race. We assume that the player's strength is 22 different, and that the high strength of each game always wins.
Input/output format
Input format:

The input file name is swiss.in.

The first line of input is three positive integers N, R, Q, separated by a space for every two numbers, indicating that there are 2*n players, R-wheel races, and the rank Q we care about.

The second line is 2*n non-negative integer s1, s2, ..., s2n, separated by a space between every two numbers, where Si represents the initial score of the contestant numbered I. The third line is 2*n positive integer w1, w2, ..., w2n, separated by a space between each two numbers, where WI represents the strength value of the player numbered I.

Output format:

The output file name is Swiss.out.

The output has only one row and contains an integer, which is the number of the player who ranked Q at the end of the R-round race.

Input/Output sample
Input Sample # #:

2 4 2
7 6 6 7
10 5 20 15

Sample # # of output:

1

Description

"Sample Interpretation"

"Data Range"

For 30% of data, 1≤n≤100;

For 50% of data, 1≤n≤10,000;

For 100% of data, 1≤n≤100,000,1≤r≤50,1≤q≤2n,0≤s1, S2, ..., s2n≤10^8,1≤w1, W2, ..., w2n≤10^8.

The 3rd question of the noip2011 popularization group.

Analysis
Good question, good question.
Naked sort will get stuck ...
We found that after each game 22 points will change, but all the winning people score is +1, all the loser scores are unchanged, so the winning person and the loser score is still in order, this time to use the two way to merge

Code

NOIP Swiss round #include <map> #include <cmath> #include <cstdio> #include <cstring> #include < Iostream> #include <algorithm> #define LL Long long #define M (a) memset (a,0,sizeof a) #define FO (i,j,k) for (i=j;i
<=k;i++) using namespace std;
const int mxn=200005; struct node {int sco,id,w;}
A[MXN],X[MXN],Y[MXN];
int n,r,q; inline bool Comp (const node &t1,const node &t2) {if (T1.sco==t2.sco) return T1.id<t2.id;return t1.sco>
T2.sco;}
    inline void Merge_sort () {int i=1,j=1,cnt=0;
        while (I<=n && j<=n) {cnt++;
        if (X[i].sco>y[j].sco) a[cnt]=x[i++];
        else if (X[i].sco<y[j].sco) a[cnt]=y[j++];
        else if (x[i].id<y[j].id) a[cnt]=x[i++];
    else a[cnt]=y[j++];
    } while (I<=n) a[++cnt]=x[i++];
while (j<=n) a[++cnt]=y[j++];
    } int main () {int i,j;
    scanf ("%d%d%d", &n,&r,&q);
    Fo (i,1,2*n) scanf ("%d", &a[i].sco);
    Fo (i,1,2*n) scanf ("%d", &AMP;A[I].W); FO (i,1,2*n) a[i].id=i;
    Sort (a+1,a+n+n+1,comp);
        while (r--) {int cnt=0;
            Fo (i,1,n) {if (A[2*I].W&GT;A[2*I-1].W) a[2*i].sco++,x[++cnt]=a[2*i],y[cnt]=a[2*i-1];
        else A[2*i-1].sco++,x[++cnt]=a[2*i-1],y[cnt]=a[2*i];
    } merge_sort ();
    } printf ("%d\n", a[q].id);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.