P1771 Swiss Turn Merge sort

Source: Internet
Author: User

Swiss Wheel

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.

Describe

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.

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 s 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 w represents the strength 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.

Ideas: Sort ~ simulate ~ Sort ~ simulate ~ sort

It's like a quick line, but it's got to be stored in vectors.

My merger is not very fast ah, but also to borrow took into the hang to a

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 6 using namespacestd;7 8 Const intM =200002;9 structUCT {Ten     intnum, W, s; One } S[m], array2[m]; A BOOLcmpConstUCT A,ConstUCT B) { -     if(A.w > B.W)return true; -     Else if(A.W = = B.W && a.num < B.num)return true; the     return false; - } - intRead () { -     intx=0, f=1;CharCh=GetChar (); +      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} +     returnx*F; A } at intN, Q, R; - voidMerge (intLowintHigh ) { -     inti =Low ; -     intMid = (low + high)/2; -     intj = mid+1; -     intK =Low ; in  -      while(I <= mid && J <=High ) { to         if(CMP (s[i], s[j])) { +array2[k++] = s[i++]; -}Else { thearray2[k++] = s[j++]; *         } $     }Panax Notoginseng      while(I <=mid) { -array2[k++] = s[i++]; the     } +      while(J <=High ) { Aarray2[k++] = s[j++]; the     } +      for(intSS = Low; SS <= High; ss++) { -S[SS] =ARRAY2[SS]; $     } $ } - voidMsort (intLowintHigh ) { -     if(Low = =High ) { theArray2[low] =S[low]; -}Else {Wuyi         intMid = (low + high)/2; the Msort (Low, mid); -Msort (mid+1, high); Wu Merge (Low, high); -     } About } $ voidSlove () { -      for(inti =0; I < n2; i + =2) { -         if(S[i].s > s[i+1].s) { -s[i].w++; A}Else { +s[i+1].w++; the         } -     } $Msort (0,2*n-1); the } the intMain () { thescanf"%d%d%d", &n, &r, &Q); the      for(inti =0; I < n2; i++) S[I].W =read (); -      for(inti =0; I < n2; i++) S[i].s =read (); in      for(inti =0; I < n2; i++) S[i].num =i; theMsort (0,2*n-1); the      while(r--) { About slove (); the     } theprintf"%d\n", s[q-1].num+1); the     return 0; +}

P1771 Swiss Turn 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.