比赛 防止isaac的小练习day1 评测结果 AAAAAAATWT
题目名称 瑞士轮 最终得分 70
用户昵称 zhjian 运行时间 2.465 s
代码语言 C++ 内存使用 3.75 MiB
提交时间 2016-11-01 11:12:30
显示代码纯文本
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#define N 100050
#define M 505
#define inf 0x3f3f3f3f
using namespace std;

int n,r,q,i,j,ji;

struct node
{
    int s,p,ii;
} a[N],w[N],l[N];

bool cmp(node a,node b)
{
    if (a.s==b.s) return a.ii<b.ii;
    return a.s>b.s;
}

int main()
{
	freopen("swiss.in","r",stdin);
	freopen("swiss.out","w",stdout);
	
    cin>>n>>r>>q;
    n*=2;
    for(i=1;i<=n;++i)
        scanf("%d",&a[i].s),a[i].ii=i;
    for (j=1;j<=n;++j)
        scanf("%d",&a[j].p);
    sort(a+1,a+1+n,cmp);
    for(ji=1;ji<=r;ji++)
    {
        int wi=1,lo=1;
        for(i=1;i<=n;i+=2)
        {
            if(a[i].p<a[i+1].p) 
				w[wi++]=a[i+1],l[lo++]=a[i];
            else if(a[i].p>a[i+1].p)
				l[lo++]=a[i+1],w[wi++]=a[i];
        }
        wi--;
        lo--;
        for(i=1;i<=n/2;i++) 
			w[i].s++;
        int x=1,y=1;
        i=0;
        while(x<=n/2&&y<=n/2)
        {
            if(w[x].s>l[y].s) 
				a[++i]=w[x++];
            if(w[x].s<l[y].s) 
				a[++i]=l[y++];
            if(w[x].s==l[y].s&&w[x].ii>l[y].ii) 
				a[++i]=l[y++];
            if(w[x].s==l[y].s&&w[x].ii<l[y].ii) 
				a[++i]=w[x++];
        }
        if(x>n/2)            
			while(y<=n/2) 
				a[++i]=l[y++];
        else 
			while(x<=n/2) 
				a[++i]=w[x++];
    }
    printf("%d",a[q].ii);
    
    fclose(stdin);
    fclose(stdout);
    
    return 0;
}