其他分享
首页 > 其他分享> > [2011年NOIP普及组] 瑞士轮

[2011年NOIP普及组] 瑞士轮

作者:互联网

首先归并排序,先比较,放入胜者组和败者组,去掉之前的分离,直接继续归并

#include<bits/stdc++.h>
using namespace std;
int n,q,bsl[2000001],bxh[2000001],bfs[2000001],ll,rr,rrr;
int i,j,ij,ii;
struct a{
int xh;
int fs;
int sl;
}a[200002],w[100002],f[100002];
void ef(int l,int r){
if(r-l>=2){
ef(l,(l+r)/2);
ef((l+r)/2+1,r);
}
for(i=l;i<=r;i++){
bsl[i]=a[i].sl;
bxh[i]=a[i].xh;
bfs[i]=a[i].fs;
}
ll=0;
rr=0;
for(i=0;i<=r-l;i++){
if(bfs[l+ll]>bfs[(l+r)/2+1+rr]&&l+ll<=(l+r)/2){
a[l+i].fs=bfs[l+ll];
a[l+i].sl=bsl[l+ll];
a[l+i].xh=bxh[l+ll];
ll++;
}
else if(rr+(r+l)/2+1>r){
a[l+i].fs=bfs[l+ll];
a[l+i].sl=bsl[l+ll];
a[l+i].xh=bxh[l+ll];
ll++;
}
else if(bfs[l+ll]==bfs[(l+r)/2+1+rr]&&l+ll<=(l+r)/2&&bxh[l+ll]<bxh[(l+r)/2+1+rr]){
a[l+i].fs=bfs[l+ll];
a[l+i].sl=bsl[l+ll];
a[l+i].xh=bxh[l+ll];
ll++;
}
else{
a[l+i].fs=bfs[rr+(r+l)/2+1];
a[l+i].sl=bsl[rr+(r+l)/2+1];
a[l+i].xh=bxh[rr+(r+l)/2+1];
rr++;
}
}
}
void bj(int s){
int ss=0;
for(i=1;i<=2*s-1;i=i+2){
ss++;
if(a[i].sl>a[i+1].sl){
w[ss].fs=a[i].fs+1;
w[ss].sl=a[i].sl;
w[ss].xh=a[i].xh;
f[ss].fs=a[i+1].fs;
f[ss].sl=a[i+1].sl;
f[ss].xh=a[i+1].xh;
}
else if(a[i].sl==a[i+1].sl&&a[i].xh<a[i+1].xh){
w[ss].fs=a[i].fs+1;
w[ss].sl=a[i].sl;
w[ss].xh=a[i].xh;
f[ss].fs=a[i+1].fs;
f[ss].sl=a[i+1].sl;
f[ss].xh=a[i+1].xh;
}
else{
f[ss].fs=a[i].fs;
f[ss].sl=a[i].sl;
f[ss].xh=a[i].xh;
w[ss].fs=a[i+1].fs+1;
w[ss].sl=a[i+1].sl;
w[ss].xh=a[i+1].xh;
}
}
}
void px(int ls,int rs){
ll=1;
rr=1;
for(ii=ls;ii<=rs;ii++){
if(w[ll].fs>f[rr].fs&&ll<=rs/2){
a[ii].fs=w[ll].fs;
a[ii].sl=w[ll].sl;
a[ii].xh=w[ll].xh;
ll++;
}
else if(rr>rs/2){
a[ii].fs=w[ll].fs;
a[ii].sl=w[ll].sl;
a[ii].xh=w[ll].xh;
ll++;
}
else if(w[ll].fs==f[rr].fs&&ll<=rs/2&&w[ll].xh<f[rr].xh){
a[ii].fs=w[ll].fs;
a[ii].sl=w[ll].sl;
a[ii].xh=w[ll].xh;
ll++;
}
else{
a[ii].fs=f[rr].fs;
a[ii].sl=f[rr].sl;
a[ii].xh=f[rr].xh;
rr++;
}
}
}
int main(){
cin>>n>>rrr>>q;
for(j=1;j<=2*n;j++){
cin>>a[j].fs;
a[j].xh=j;
}
for(j=1;j<=2*n;j++){
cin>>a[j].sl;
}
ef(1,2*n);

for(ij=1;ij<=rrr;ij++){
bj(n);
px(1,2*n);
}
cout<<a[q].xh;
}

标签:普及,fs,rr,NOIP,ss,ll,xh,sl,2011
来源: https://www.cnblogs.com/wangjunlong9948/p/16581967.html