社区讨论

70pts求助

P1309[NOIP 2011 普及组] 瑞士轮参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lobkep8p
此快照首次捕获于
2023/10/29 22:27
2 年前
此快照最后确认于
2023/11/04 03:25
2 年前
查看原帖
如题,样例过了,RE了三个点
CPP
#include<iostream>
#include<algorithm>
#define dehere for(int i=1;i<=n;i++)cout<<st[i].k<<' '<<st[i].sc<<'\n'
using namespace std;
int n,r,q;
struct node{int sc,pw,k;}st[100005];
bool cmp(node a,node b){return a.sc==b.sc?a.k<b.k:a.sc>b.sc;}
int main(){
    cin>>n>>r>>q;
    for(int i=1;i<=n*2;i++)scanf("%d",&st[i].sc);
    for(int i=1;i<=n*2;i++)scanf("%d",&st[i].pw);
    for(int i=1;i<=n*2;i++)st[i].k=i;
    sort(st+1,st+n*2+1,cmp);
    while(r--){
        node win[n+1],los[n+1];
        for(int i=1;i<=n;i++){
            if(st[i*2-1].pw>st[i*2].pw){
                st[i*2-1].sc++;
                win[i]=st[i*2-1];
                los[i]=st[i*2];
            }else{
                st[i*2].sc++;
                win[i]=st[i*2];
                los[i]=st[i*2-1];
            }
        }
        int idxw=1,idxl=1,idx=0;
        while(idxw<=n&&idxl<=n){
            if(cmp(win[idxw],los[idxl]))st[++idx]=win[idxw++];
            else st[++idx]=los[idxl++];
        }
        while(idxw<=n)st[++idx]=win[idxw++];
        while(idxl<=n)st[++idx]=los[idxl++];
    }
    cout<<st[q].k<<endl;
    return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...