[C] 纯文本查看 复制代码 #include<bits/stdc++.h>
using namespace std;
int N,R,Q,n;
struct player{
int no;
int score;
int power;
}p[200001],win[100001],lost[100001];
bool cmp(player a,player b)
{
if(a.score!=b.score)
return a.score>b.score;
else
return a.no<b.no;
}
void way1()//方法1 sort
{
sort(p+1,p+n+1,cmp);
for(int i=1;i<=R;i++){
for(int j=1;j<=N;j++){
if(p[2*j].power>p[2*j-1].power)
p[2*j].score++;
else
p[2*j-1].score++;
}
sort(p+1,p+n+1,cmp);
}
}
void way2()//方法2 归并
{
sort(p+1,p+n+1,cmp);
int w=1,l=1,t=1;
for(int i=1;i<=R;i++){
for(int j=1;j<=N;j++){
if(p[2*j].power>p[2*j-1].power){
p[2*j].score++;
win[j]=p[2*j];
lost[j]=p[2*j-1];
}
else{
p[2*j-1].score++;
win[j]=p[2*j-1];
lost[j]=p[2*j];
}
}
w=1;
l=1;
t=1;
while(w<=N && l<=N)
{
if(cmp(win[w],lost[l]))
p[t++]=win[w++];
else
p[t++]=lost[l++];
}
while(w<=N) p[t++]=win[w++];
while(l<=N) p[t++]=lost[l++];
}
}
int main()
{
cin>>N>>R>>Q;
n=2*N;
for(int i=1;i<=n;i++){
cin>>p[i].score;
p[i].no=i;
}
for(int i=1;i<=n;i++)
cin>>p[i].power;
//way1();
way2();
cout<<p[Q].no;
return 0;
} |