Rokua p1309--Swiss Wheel (merge sort)

Source: Internet
Author: User

Https://www.luogu.org/problem/show?pid=1309#sub

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 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 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 # #:
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.

It's not going to be a quick row.

and time complexity O (n).

Losers and winners are ordered separately.

STL Dafa is good.

1#include <bits/stdc++.h>2 using namespacestd;3 structnode4 {5     intnum;6     intSoc;7}a1[200050],a2[200050],a[200050];8 BOOLCMP (node X,node y)9 {Ten     if(X.SOC!=Y.SOC)returnX.soc>Y.soc; One     returnx.num<Y.num; A } - intMain () - { the     intn,r,q,val[200050]; -Cin>>n>>r>>Q; -n*=2; -      for(intI=0; i<n;i++) +     { -Cin>>A[i].soc; +a[i].num=i; A     } atSort (a,a+n,cmp); -      for(intI=0; i<n;i++) -Cin>>Val[i]; -      for(intI=0; i<r;i++) -     { -          for(intj=1; j<=n/2; j + +) in         if(val[a[j*2-2].num]>val[a[j*2-1].num]) -         { toa[j*2-2].soc++; +a1[j-1]=a[j*2-2]; -a2[j-1]=a[j*2-1]; the         } *         Else $         {Panax Notoginsenga[j*2-1].soc++; -a1[j-1]=a[j*2-1]; thea2[j-1]=a[j*2-2]; +         } AMerge (a1,a1+n/2, a2,a2+n/2, a,cmp); the     } +cout<<a[q-1].num+1<<Endl; -     return 0; $}


Rokua p1309--Swiss Wheel (merge sort)

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.