Codevs 1132 Swiss Wheel

Source: Internet
Author: User

Title Description Description

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.

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.

Enter a description Input Description

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 description Output Description

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.

Sample input Sample Input

2 4 2
7 6 6 7
10 5 20 15

Sample output Sample Output

1

Data range and Tips Data Size & Hint

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≤108,1≤w1,w2, ..., w2n≤108.

Thinking of solving problems

About the problem ... I just want to laugh and not talk, the first time to do this question I decided to choose the R-speed, and then decisively take a 50 points, and then the children's shoes told me that only need to build two arrays, a storage plus points, a storage no extra points, and then merge the sort, the original O (Nlogn) to the complexity of O (n), you can easily card the maximum. Then I successfully knocked out the code, and later debugging but!!! Why is that? After arduous n-Times debugging I found that my merge sort did not bring back the values that did not enter the original array in the loop, resulting in an error!!! Be sure to look at the merge sort again!!!

 ProgramSwiss;typepeo=RecordW,s,no:longint; End;varPeArray[0..200000] ofPEO; W,f:Array[1..200000] ofPEO; N,r,q1,i,j,sum:longint;procedureSort (l,r:longint);//Multi-keyword quick-linevarI,j,x,y:longint; beginI:=M; J:=R; X:=pe[(L+r)Div 2].s; Y:=pe[(L+r)Div 2].no; Repeat            while(pe[i].s>x)or((X=PE[I].S) and(y>pe[i].no)) DoInc (I);  while(X&GT;PE[J].S)or((X=PE[J].S) and(y<pe[j].no)) DoDec (j); if  not(I&GT;J) Then             beginpe[0]:=Pe[i]; Pe[i]:=Pe[j]; PE[J]:=pe[0];                Inc (I); J:=j-1; End; untilI>J; ifL<j Thensort (l,j); ifI<r Thensort (i,r); End;procedureguibing;//MergevarQ,p,sum1,k:longint;beginQ:=1; P:=1; SUM1:=0;  while(q<=n) and(p<=n) Do    begin    if(W[Q].S&GT;F[P].S)or((W[Q].S=F[P].S) and(w[q].no<f[p].no)) Then    beginInc (SUM1); PE[SUM1]:=W[q];    Inc (Q); End; if(W[Q].S&LT;F[P].S)or((W[Q].S=F[P].S) and(w[q].no>f[p].no)) Then    beginInc (SUM1); PE[SUM1]:=F[p];    Inc (P); End; End; ifq=n+1  Then//It 's embarrassing to be wrong here . forK:=p toN Do       beginInc (SUM1); PE[SUM1]:=F[k]; End       Else        forK:=q toN Do       beginInc (SUM1); PE[SUM1]:=W[k]; End;End;beginread (N,R,Q1);  fori:=1  to 2*n Dope[i].no:=i;  fori:=1  to 2*n Doread (PE[I].S);  fori:=1  to 2*n Doread (PE[I].W); Sort (1,2*N); pe[0].no:=0;  forj:=1  toR Do    beginI:=1; Sum:=0;  whilei<=2*n Do        beginInc (SUM); ifpe[i].w>pe[i+1].w Then            beginInc (PE[I].S); W[sum]:=Pe[i]; F[sum]:=pe[i+1]; End            Else            beginInc (Pe[i+1].s); W[sum]:=pe[i+1]; F[sum]:=Pe[i]; End; I:=i+2; End;    guibing; End; Writeln (pe[q1].no);End.

Codevs 1132 Swiss Wheel

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.