瑞士轮(改编版)求debug我的代码粘在下面

描述
在双人对决的竞技性比赛,如乒乓球、羽毛球、国际象棋中,最常见的赛制是淘汰赛和循环赛。前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高。后者的特点是较为公平,偶然性较低,但比赛过程往往十分冗长。 本题中介绍的瑞士轮赛制,因最早使用于1895年在瑞士举办的国际象棋比赛而得名。它可以看作是淘汰赛与循环赛的折中,既保证了比赛的稳定性,又能使赛程不至于过长。N 名 (N 为偶数)编号为 1∼N 的选手共进行 R 轮比赛。每轮比赛开始前,以及所有比赛结束后,都会按照总分从高到低对选手进行一次排名。选手的总分为第一轮开始前的初始分数加上已参加过的所有比赛的得分和。总分相同的,约定编号较小的选手排名靠前。 每轮比赛的对阵安排与该轮比赛开始前的排名有关:第1 名和第2 名、第 3 名和第 4名、等等(不让用省略号用等等代替)、第 2K−1 名和第 2K 名、等等(不让用省略号用等等代替) 、第 N−1 名和第 N 名,各进行一场比赛。每场比赛胜者得 1分,负者得 0分。也就是说除了首轮以外,其它轮比赛的安排均不能事先确定,而是要取决于选手在之前比赛中的表现。 现给定每个选手的初始分数及其实力值,试计算在R 轮比赛过后,排名第 Q 的选手编号是多少。我们假设选手的实力值两两不同,且每场比赛中实力值较高的总能获胜。

输入INPUT:
输入格式
输入共 3 行
第一行是三个正整数 N,R,Q 每两个数之间用一个空格隔开,表示有 N 名选手、R 轮比赛,以及我们关心的名次 Q。
第二行是 N 个非负整数s[1] , s[2],等等(不让用省略号用等等代替) , s[N]。每两个数之间用一个空格隔开,其中 s[i] 表示编号为i 的选手的初始分数。
第三行是 N 个正整数 w[1] , w[2] ,等等(不让用省略号用等等代替), w[N],每两个数之间用一个空格隔开,其中 w[i] 表示编号为 i 的选手的实力值。

数据范围:

  • 1<=N<=200,000 且 N 为偶数
  • 1<=R<=50
  • 1<=Q<=N
  • 0<=s1,s2,等等(不让用省略号用等等代替),sn <=10^8
  • 1<=w1,w2,等等(不让用省略号用等等代替),wn <=10^8

输入样例
4 4 2
7 6 6 7
10 5 20 15

输出OUTPUT:
输出格式
一个整数,即 R 轮比赛结束后,排名第 Q 的选手的编号。

输出样例
1

我的代码,求debug急:

#include<iostream>
#include<algorithm>
using namespace std;
int n,r,q;
struct Info{
 int num,s,w;
}tot[100005],win[100005],los[100005];
bool cmp(Info a,Info b){
 if(a.s==b.s)return a.num<b.num;
 else return a.s>b.s;
}
void merge(){
 int pw=0,pl=0,pt=0; 
 for(int i=1;i<n;i+=2){
  if(tot[i].w>tot[i+1].w){
   tot[i].s++;
   win[++pw]=tot[i];
   los[++pl]=tot[i+1];
  }else{
   tot[i+1].s++;
   win[++pw]=tot[i+1];
   los[++pl]=tot[i];
  }   
 }
 pw=1,pl=1,pt=1;
 while(pw<=n&&pl<=n){
  if(cmp(win[pw],los[pl]))tot[pt++]=win[pw++];
  else tot[pt++]=los[pl++];
 }
 while(pw<=n)tot[pt++]=win[pw++]; 
 while(pl<=n)tot[pt++]=los[pl++];
}
int main(){
 cin>>n>>r>>q;
 for(int i=1;i<=n;i++){cin>>tot[i].s;tot[i].num=i;}
 for(int i=1;i<=n;i++)cin>>tot[i].w;
 sort(tot+1,tot+1+n,cmp);
 for(int i=1;i<=r;i++)merge();
 cout<<tot[q].num<<endl;
 return 0;
}

看一下,运算出你的结果了

img

#include <algorithm>
#include <iostream>

using namespace std;
int n, r, q;
struct Info {
    int num, s, w;
} tot[100005], win[100005], los[100005];
bool cmp(Info a, Info b) {
    if (a.s == b.s)
        return a.num < b.num;
    else
        return a.s > b.s;
}
void merge() {
    int pw = 0, pl = 0, pt = 0;
    for (int i = 1; i < n; i += 2) {
        if (tot[i].w > tot[i + 1].w) {
            tot[i].s++;
            win[++pw] = tot[i];
            los[++pl] = tot[i + 1];
        } else {
            tot[i + 1].s++;
            win[++pw] = tot[i + 1];
            los[++pl] = tot[i];
        }
    }
    pw = 1, pl = 1, pt = 1;
    while (pw <= n && pl <= n) {
        if (cmp(win[pw], los[pl]))
            tot[pt++] = win[pw++];
        else
            tot[pt++] = los[pl++];
    }
    while (pw <= n)
        tot[pt++] = win[pw++];
    while (pl <= n)
        tot[pt++] = los[pl++];
}
int main() {
    cin >> n >> r >> q;
    for (int i = 1; i <= n; i++) {
        cin >> tot[i].s;
        tot[i].num = i;
    }
    for (int i = 1; i <= n; i++)
        cin >> tot[i].w;
    sort(tot + 1, tot + 1 + n, cmp);
    for (int i = 1; i <= r; i++)
        merge();
    cout << tot[q].num << endl;
    return 0;
}