求助!!!
查看原帖
求助!!!
553640
Konjac0629楼主2023/8/28 16:37

RT,样例也过不了,输出4,不知道哪里出问题了

#include <bits/stdc++.h>

using namespace std;

struct person
{
    int nom;
    int score;
    int strength;
    bool operator<(const person &a) const
    {
        return score > a.score || (score == a.score && nom < a.nom);
        // 上面省略了 this 指针,完整表达式如下:
        // this->score<a.score||(this->score==a.score&&this->name>a.name);
    }
};
vector<person> people(1000001), winner(1000001), loser(1000001);

bool cmp(person a, person b)
{
    if (a.score == b.score)
        return a.nom < b.nom;
    else
        return a.score > b.score;
}

int main()
{
    int N, R, Q;
    cin >> N >> R >> Q;
    for (int i = 0; i < 2 * N; i++)
    {
        people[i].nom = i + 1;
        cin >> people[i].score;
    }
    for (int j = 0; j < 2 * N; j++)
    {
        cin >> people[j].strength;
    }
    sort(people.begin(), people.begin() + 2 * N, cmp);
    for (int k = 0; k < R; k++)
    {
        int t = 0;
        for (int m = 0; m < 2 * N; m = m + 2)
        {
            if (people[m].strength > people[m + 1].strength)
            {
                people[m].score++;
                winner[t] = people[m];
                loser[t] = people[m + 1];
            }
            else if (people[m].strength < people[m + 1].strength)
            {
                people[m + 1].score++;
                winner[t] = people[m + 1];
                loser[t] = people[m];
            }
        }
        merge(winner.begin(), winner.begin() + 2 * N, loser.begin(), loser.begin() + 2 * N, back_inserter(people));
    }
    cout << people[Q - 1].nom << endl;
    return 0;
}
2023/8/28 16:37
加载中...