Luogu P1309 Swiss Wheel "sort"

Source: Internet
Author: User

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

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.

Cool analysis

The most violent of all is that every battle is structured quickly, but it's too slow, 60 points.

By our cool analysis can find some special properties, that is, once battle down, because there are "integral order", so the new rankings will not be too big changes. In the case of the card sort, we can consider a stable merge, O (NLOGN);

A class mergesort is used here;

Comments are written in the code.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 intn,r,e;6 structnode7 {8     intScore,pos,abi;9 };TenNode q[200002],win[200002],lose[200002];//win and lose are guaranteed to be orderly.  One BOOLCMP (node A,node b) A { -     if(A.score==b.score)returna.pos<B.pos; -     returnA.score>B.score; the } - voidmerge () -{//class Merge -     inttmp=n/2;//attention. The number of elements in win and lose is TMP +     intI=1, j=1, k=1; -      while(i<=tmp&&j<=tmp) +     { A         if(win[i].score>lose[j].score| | (win[i].score==lose[j].score&&win[i].pos<lose[j].pos)) at         { -q[k]=Win[i]; -i++;k++; -         } -         Else -         { inq[k]=Lose[j]; -j++;k++; to          }  +}//the following while loop either executes the first or executes the second because there is always a condition that does not conform when the previous loop jumps out.  -      while(i<=tmp) the     { *q[k]=Win[i]; $i++;k++;Panax Notoginseng     } -      while(j<=tmp) the     { +q[k]=Lose[j]; Aj++;k++; the      }  + } - intMain () $ { $scanf"%d%d%d",&n,&r,&e); -n=2*n;//Small Details -      for(intI=1; i<=n;i++) the     { -scanf"%d",&q[i].score);WuyiQ[i].pos=i;//POS Represents the initial number the     } -      for(intI=1; i<=n;i++) scanf ("%d",&Q[i].abi); WuSort (q+1, q+n+1, CMP); -      for(intI=1; i<=r;i++) About{//Num represents the first few battle and its results.  $         intnum=0;//Note that NUM is used for one battle down, one battle to go through the following loop, notice the definition of the position.  -          for(intj=1; j<=n;j+=2)//The step size is added to 2. -         { -             if(q[j].abi>q[j+1].abi) A             { +Q[j].score + +; thenum++; -WIN[NUM]=Q[J];//Num winning man $lose[num]=q[j+1];//the first num loser. the             } the             Else the             { theq[j+1].score + +; -num++; inwin[num]=q[j+1]; thelose[num]=Q[j]; the             } About         } theMerge ();//22 Battle Post-unification sorting the     } theprintf"%d", Q[e].pos); +     return 0; -}
View Code

Boulevard to Jane!

Luogu P1309 Swiss Wheel "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.