P1309 瑞士轮 (吸氧了)

P1309 瑞士轮

题解

1.这题可以模拟一下

2.sort吸氧可以过(可能是排序有点慢吧,不开会T)

   sort排序时注意:

    return 1 是满足条件,不交换

    return 0是不满足,交换

代码(吸氧优化了一下QWQ)

// luogu-judger-enable-o2
#include<bits/stdc++.h>

using namespace std;

int n,r,q;
struct node
{
    int s,num,w;
}peo[200002];

bool cmp(node x,node y)
{
    if(x.s >y.s ) return 1;
    if(x.s <y.s ) return 0;
    if(x.s ==y.s )
    {
        if(x.num <y.num ) return 1;
        else return 0;
    }
    
}

int main()
{
    scanf("%d%d%d",&n,&r,&q);
    n=2*n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&peo[i].s );
        peo[i].num =i;
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&peo[i].w );
    
    for(int k=1;k<=r;k++)
    {
        sort(peo+1,peo+n+1,cmp);
        for(int i=1;i<=n;i+=2)
        {
            if(peo[i].w <peo[i+1].w ) peo[i+1].s ++;
            else peo[i].s ++;
        }

    }
    
    sort(peo+1,peo+n+1,cmp);
    
    printf("%d",peo[q].num );
    
}
原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/11029596.html