Valley 1309 Swiss Wheel

Source: Internet
Author: User

Valley 1309 Swiss Wheel

Address: http://www.luogu.org/problem/show?pid=1309

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/Output sample

Input Sample # #:

2 4 2

7 6 6 7

10 5 20 15

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.

Ideas

Sort + Merge.

First according to the initial fractional s to sort, after the order of the simulation of each game to win and lose to store the winners and losers, where win and lose are ordered series is still in accordance with the order of s from large to small, the two ordered series of merging and then the next round of competition.

The sort time is O (Nlogn). Enumeration + Time to merge is O (NR).

Because the data n<=100000, so you can consider the read-in optimization, write a read_int, the total time is reduced by about 400ms, very considerable.

Code

1#include <iostream>2#include <cstdio>3#include <vector>4#include <cstring>5#include <algorithm>6 #definefor (A,B,C) for (int a= (b);a< (c); a++)7 using namespacestd;8 9 Const intMAXN =200000+Ten;Ten  One structnode{ A     intS,w,rank; -      -     BOOL operator< (ConstNODE&AMP;RHS)Const{ the         if(S!=RHS.S)returnS>RHS.S; -         returnrank<Rhs.rank; -     } - }NODES[MAXN],TMP[MAXN]; +  - intn,r,q; +vector<int>Win,lose; A  atInlinevoidmerge () { -     intp=0, P_end=win.size (), q=0, Q_end=lose.size (), i=0; -      while(P<p_end | | q<q_end) { -         if(Q>=q_end | | p<p_end&& (nodes[win[p]].s>nodes[lose[q]].s| | (Nodes[win[p]].s==nodes[lose[q]].s && nodes[win[p]].rank<Nodes[lose[q]].rank ))) -tmp[i++]=nodes[win[p++]]; -         Elsetmp[i++]=nodes[lose[q++]]; in     } -for (I,0, N) nodes[i]=Tmp[i]; to } +  -InlineintRead_int () { the     CharC C=GetChar (); *      while(!isdigit (c)) c=GetChar (); $     Panax Notoginseng     intx=0; -      while(IsDigit (c)) { thex=x*Ten+c-'0'; +C=GetChar (); A     } the     returnx; + } -  $ intMain () { $Freopen ("swiss.in","R", stdin); -Freopen ("Swiss.out","W", stdout); -      theN=read_int (); R=read_int (); q=read_int (); -n*=2;Wuyifor (I,0, N) nodes[i].s=read_int (); thefor (I,0, N) Nodes[i].w=read_int (), nodes[i].rank=i+1; -Sort (nodes,nodes+N); Wu      while(r--) -     { About win.clear (); Lose.clear (); $               for(intI=0; i<n;i+=2) -                if(nodes[i].w>nodes[i+1].W | | (nodes[i].w==nodes[i+1].W && nodes[i].rank<nodes[i+1].rank)) { -nodes[i].s++; - Win.push_back (i); ALose.push_back (i+1); +                } the              Else { -nodes[i+1].s++; $Win.push_back (i+1); the Lose.push_back (i); the              } the merge (); the     } -printf"%d", nodes[q-1].rank); in     return 0; the}

Valley 1309 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.