QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#580078#9370. Gambling on Choosing RegionalsegmontCompile Error//C++231.7kb2024-09-21 19:59:412024-09-21 19:59:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-21 19:59:42]
  • 评测
  • [2024-09-21 19:59:41]
  • 提交

answer

#include <algorithm>
#include <string>
#include <unordered_map>
#include <iostream>
#include <vector>
using namespace std;

struct Team {
    int strength;
    string uni;
    int rank;
    int id;
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> c(k);
    for (int i = 0; i < k; ++i) {
        cin >> c[i];
    }
    vector<Team> teams(n);
    for (int i = 0; i < n; ++i) {
        cin >> teams[i].strength >> teams[i].uni;
        teams[i].id = i;
        teams[i].rank = -1; // 初始化排名
    }

    // 根据队伍的实力排序,实力高的在前
    sort(teams.begin(), teams.end(), [](const Team &a, const Team &b) {
        return a.strength > b.strength;
    });
    for (int i = 0; i < n; ++i) {
        int bestRank = INT_MAX;
        for (int j = 0; j < k; ++j) {
            int currentRank = 0;
            unordered_map<string, int> uniCount;
            for (int m = 0; m < i; ++m) {
                if (teams[m].rank == j) {
                    uniCount[teams[m].uni]++;
                }
            }
            if (uniCount[teams[i].uni] < c[j]) {
                currentRank += 1; // 队伍i可以被分配到竞赛j
                for (int m = i + 1; m < n; ++m) {
                    if (teams[m].strength > teams[i].strength) {
                        currentRank += 1;
                    }
                }
                bestRank = min(bestRank, currentRank);
            }
        }
        teams[i].rank = bestRank;
    }

    // 输出每个队伍的最坏情况下的最小排名
    for (const auto &team : teams) {
        cout << team.rank << endl;
    }

    return 0;
}

    

詳細信息

answer.code: In function ‘int main()’:
answer.code:34:24: error: ‘INT_MAX’ was not declared in this scope
   34 |         int bestRank = INT_MAX;
      |                        ^~~~~~~
answer.code:6:1: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
    5 | #include <vector>
  +++ |+#include <climits>
    6 | using namespace std;