Topic background
In the double duel of competitive games, such as table tennis, badminton, chess, the game system is the most common knockout and round robin. The former is characterized by a small number of the playing field, every game exciting, but a higher chance. The latter is characterized by relatively fair, low chance, but the race is often very lengthy.
This problem is described in Swiss round game system, due to the use of the first chess tournament held in Switzerland in 1895 and named. It can be seen as a compromise with the knockout round robin, both to ensure the stability of the game, but also make the race will not be too long.
Title Description
2 × N number 1~2N players were a total of R round. Before the start of each round, and the end of all the games, players will be out to follow a descending rank. The initial player total score is the score before the start of the first round plus has participated in all competitions and scoring. The same score, the agreed number of smaller players ranking.
Against arrange each round with the top of the round began about: 1st and 2nd, 3rd and 4th, ......, the first 2K-1 and No. 2K name, ......, the first 2N-1 name and 2N first name, each for a game. Every game winner gets 1 point, the loser 0 points. That is in addition to the first round, another round of arrangement can not be determined in advance, but will depend on the performance of players before the game.
Now given the initial value of the score and the strength of each player, calculate R after round, a player ranked No. Q number is. We assume that the value of the player's strength pairwise disjoint, and high strength values in every game always wins.
Input Format
The first three lines are positive integers N, R, Q, each separated by a space between the two numbers, there are 2 × N represents players, R rounds, we are concerned and ranking Q.
The second line is the 2 × N non-negative integers s1, s2, ..., s2N, between every two numbers separated by a space, where si represents the number of players initial score ii. The third line is the 2 × N positive integers w1, w 2, ..., w2N, between every two numbers separated by a space, where wi represents the number i of the strength values of the players.
Output Format
An integer that is the end of the round R, Q ranked player number.
Sample input and output
Input # 1
2 4 2
7 6 6 7
10 5 20 15
Output # 1
1
Description / Tips
Sample [explain]
【data range】
For 30% 30% of the data, 1≤N≤100;
50% 50% For the data, 1≤N≤10,000;
To 100% 100% data, 100,000, 1. 1 ≤ N ≤ 50, 1 ≤ Q ≤ ≤ ≤ R & lt 2N, 0 ≤ S_1, S_2, ..., 2N S_ {} ≦ 10 . 8 , ≤w_1. 1, w_2, ..., ≤ 10} {2N W_ . 8 .
noip2011 popularity of Group 3 questions.
Thinking
Beginning with fast row sort () a row in the end, then there are four points of overtime, then for stable_sort (), the result was a timeout with three points, and finally had to use merge sort, but fortunately there are merge () This artifact, or else uncomfortable.
Source
#include<bits/stdc++.h>
using namespace std;
class person
{
public:
long long int id, scare, num;
};
person s[200001], a[200001], b[200001];
bool cmp(person a, person b)
{
if(a.scare != b.scare)
return a.scare > b.scare;
return a.id < b.id;
}
int main()
{
int N, R, Q;
cin >> N >> R >> Q;
for (int i = 0; i < 2 * N; i++)
{
s[i].id = (long long int)i + 1;
cin >> s[i].scare;
}
for (int i = 0; i < 2 * N; i++)
cin >> s[i].num;
sort(s, s + 2 * N, cmp);
int t1;
for (int i = 0; i < R; i++)
{
t1 = 0;
for (int j = 0; j < 2 * N; j += 2)
{
if (s[j].num > s[j + 1].num)
{
a[t1].id = s[j].id;
a[t1].num = s[j].num;
a[t1].scare = s[j].scare + 1;
b[t1].id = s[j+1].id;
b[t1].num = s[j+1].num;
b[t1].scare = s[j+1].scare;
t1++;
}
else
{
a[t1].id = s[j+1].id;
a[t1].num = s[j+1].num;
a[t1].scare = s[j+1].scare + 1;
b[t1].id = s[j].id;
b[t1].num = s[j].num;
b[t1].scare = s[j].scare;
t1++;
}
}
merge(a, a + t1, b, b + t1, s, cmp);
}
cout << s[Q-1].id;
return 0;
}