1 条题解

  • 1
    @ 2023-9-17 17:23:26
    #include <iostream>
    #include <algorithm>
    const int N = 1e6 + 5;
    int n, r, q;
    int a[N], winner[N], loser[N];
    int s[N], w[N];
    bool cmp(int x, int y)
    {
        if (s[x] == s[y])
            return x < y;
        return s[x] > s[y];
    }
    void MergeSort()  // 归并排序
    {
        int i, j;
        i = j = 1;
        a[0] = 0;
        while(i <= winner[0] && j<=loser[0]) // 归并排序的核心
        {
            if (cmp(winner[i], loser[j]))
                a[++a[0]] = winner[i++];
            else
                a[++a[0]] = loser[j++];
        }
        while (i <= winner[0])
            a[++a[0]] = winner[i++];
        while (j <= loser[0])
            a[++a[0]] = loser[j++];
    }
    int main()
    {
        std::ios::sync_with_stdio(false); // 读入加速
        std::cin.tie(NULL);
        std::cout.tie(NULL);
        std::cin >> n >> r >> q; // 输入数据
        n *= 2;
        for (int i = 1; i <= n; i++)
            a[i] = i;
        for (int i = 1; i <= n; i++)
            std::cin >> s[i];
        for (int i = 1; i <= n; i++)
            std::cin >> w[i];
        std::sort(a + 1, a + n + 1, cmp);
        for (int i = 1; i <= r; i++)
        {
            winner[0] = loser[0] = 0;
            for (int j = 1; j <= n; j += 2)
            {
                if (w[a[j]] > w[a[j + 1]])
                {
                    s[a[j]]++;
                    winner[++winner[0]] = a[j];
                    loser[++loser[0]] = a[j + 1];
                }
                else
                {
                    s[a[j + 1]]++;
                    winner[++winner[0]] = a[j + 1];
                    loser[++loser[0]] = a[j];
                }
            }
            MergeSort(); // 开始归并排序
        }
        std::cout << a[q]; // 输出第q名选手的编号
        return 0;
    }
    

    本人方法比较拙劣,各位不喜勿喷

    • 1

    信息

    ID
    1177
    时间
    1000ms
    内存
    16MiB
    难度
    9
    标签
    递交数
    10
    已通过
    5
    上传者