用sort会超时,显而易见。

然后想到了归并。至于为什么把运动员分成输与赢两组,我也不是很清楚,也许换种方式分组也行,但是分成输与赢两组更容易分组与合并。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = 500005;
int Set() {
int a = 0;
bool minus = false;
char ch = getchar();
while (!(ch == '-' || (ch >= '0' && ch <= '9'))) ch = getchar();
if (ch == '-') {
minus = true;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
a = a * 10 + (ch - '0');
ch = getchar();
}
if (minus) a = -a;
return a;
}
struct As {
int Num;
int Score,Level;
inline bool operator < (const As a) const {
if(Score != a.Score) {
return Score > a.Score;
}
return Num < a.Num;
}
} Man[MAXN],Win[MAXN],Lose[MAXN];
inline void Merge(int Endw,int Endl) {
int Stax = 1,Stay = 1,Lgt = 0;
while(Stax <= Endw && Stay <= Endl) {
if(Win[Stax].operator <(Lose[Stay])) {
Man[++Lgt] = Win[Stax++];
} else {
Man[++Lgt] = Lose[Stay++];
}
}
while(Stax <= Endw) {
Man[++Lgt] = Win[Stax++];
}
while(Stay <= Endl) {
Man[++Lgt] = Lose[Stay++];
}
}
int main() {
int N,Q,R;
scanf("%d%d%d",&N,&R,&Q);
N *= 2;
for(int i = 1; i<=N; i++) {
Man[i].Num = i;
Man[i].Score = Set();
}
for(int i = 1; i<=N; i++) {
Man[i].Level = Set();
}
sort(Man + 1,Man + N + 1);
for(int i = 1; i<=R; i++) {
int Now = 1,Lw = 0,Ll = 0;
while(Now <= N) {
if(Man[Now].Level > Man[Now + 1].Level) {
Man[Now].Score ++;
Win[++Lw] = Man[Now];
Lose[++Ll] = Man[Now + 1];
} else {
Man[Now + 1].Score ++;
Win[++Lw] = Man[Now + 1];
Lose[++Ll] = Man[Now];
}
Now += 2;
}
Merge(Lw,Ll);
}
printf("%d\n",Man[Q].Num);
return 0;
}
05-08 15:11