Do too little today, put a little problem dine 233
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 and Output Sample input example # #:
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.
Simulate R wheel, sort after each round end.
At first I didn't think of a bunch of sort hitting up, pretty tle.
After the discovery or use merge good write. Take this opportunity to discover that the STL library has merge sort function merges. STL Dafa Good!
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn=210000;9 intn,r,q;Ten structnode{ One intPW; A intscore; - intnum; -}A[MXN],W[MXN],F[MXN];//all the winners are losers . the intCMP (node A,node b) { - if(A.score!=b.score)returnA.score>B.score; - returna.num<B.num; - } + intMain () { -scanf"%d%d%d",&n,&r,&q); +n=n*2; A inti,j; at for(i=1; i<=n;i++){ -scanf"%d",&a[i].score); - } - for(i=1; i<=n;i++){ -scanf"%d",&A[I].PW); -a[i].num=i; in } -Sort (A +1, a+n+1, CMP); to + for(i=1; i<=r;i++){ - for(j=1; j<=n;j+=2){ the if(a[j].pw>a[j+1].pw) { *w[(j+1) >>1]=A[j]; $f[(j+1) >>1]=a[j+1];Panax Notoginseng } - Else{ thew[(j+1) >>1]=a[j+1]; +f[(j+1) >>1]=A[j]; A } thew[(j+1) >>1].score++; + } -Merge (w+1, w+n/2+1, f+1, f+n/2+1, A +1, CMP); $ } $printf"%d\n", a[q].num); - return 0; -}
NOIP2011 Universal group T3 Rokua P1309 Swiss wheel