QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#565681 | #9308. World Cup | shumian | Compile Error | / | / | C++20 | 3.7kb | 2024-09-15 22:00:30 | 2024-09-15 22:00:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
// 返回中国队在给定分组中的最佳结果
int simulate(vector<int>& strengths) {
// 将中国队放在所有可能的小组中,计算最好的结果
int china_strength = strengths[0];
vector<int> results = {32, 16, 8, 4, 2, 1}; // 从最差到最好
// 检查所有分组方式
for (int mask = 0; mask < (1 << 31); ++mask) {
vector<int> groups[8];
for (int i = 0; i < 32; ++i) {
int group = (mask >> (i * 2)) & 3;
groups[group].push_back(strengths[i]);
}
// 对每组球队按实力值排序
for (int i = 0; i < 8; ++i) {
sort(groups[i].rbegin(), groups[i].rend());
}
// 找出每组前两名
vector<int> winners;
for (int i = 0; i < 8; ++i) {
winners.push_back(groups[i][0]); // 第一名
winners.push_back(groups[i][1]); // 第二名
}
// 淘汰赛
vector<int> round16 = {winners[0], winners[1], winners[2], winners[3], winners[4], winners[5], winners[6], winners[7],
winners[8], winners[9], winners[10], winners[11], winners[12], winners[13], winners[14], winners[15]};
// 检查淘汰赛结果
vector<int> next_round;
for (int i = 0; i < 16; i += 2) {
if (round16[i] == china_strength || round16[i + 1] == china_strength) {
next_round.push_back(max(round16[i], round16[i + 1]));
} else {
next_round.push_back(max(round16[i], round16[i + 1]));
}
}
if (find(next_round.begin(), next_round.end(), china_strength) == next_round.end()) continue;
// 8强
round16 = next_round;
next_round.clear();
for (int i = 0; i < 8; i += 2) {
if (round16[i] == china_strength || round16[i + 1] == china_strength) {
next_round.push_back(max(round16[i], round16[i + 1]));
} else {
next_round.push_back(max(round16[i], round16[i + 1]));
}
}
if (find(next_round.begin(), next_round.end(), china_strength) == next_round.end()) continue;
// 4强
round16 = next_round;
next_round.clear();
for (int i = 0; i < 4; i += 2) {
if (round16[i] == china_strength || round16[i + 1] == china_strength) {
next_round.push_back(max(round16[i], round16[i + 1]));
} else {
next_round.push_back(max(round16[i], round16[i + 1]));
}
}
if (find(next_round.begin(), next_round.end(), china_strength) == next_round.end()) continue;
// 决赛
round16 = next_round;
next_round.clear();
for (int i = 0; i < 2; i += 2) {
if (round16[i] == china_strength || round16[i + 1] == china_strength) {
next_round.push_back(max(round16[i], round16[i + 1]));
} else {
next_round.push_back(max(round16[i], round16[i + 1]));
}
}
if (find(next_round.begin(), next_round.end(), china_strength) == next_round.end()) continue;
// 输出最好的结果
return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)];
}
return 32; // 未能晋级到淘汰赛阶段
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
vector<int> strengths(32);
for (int i = 0; i < 32; ++i) {
cin >> strengths[i];
}
cout << simulate(strengths) << '\n';
}
return 0;
}
详细
answer.code: In function ‘long long int simulate(std::vector<long long int>&)’: answer.code:84:27: error: no matching function for call to ‘min(int, long long int)’ 84 | return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)]; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)’ 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: answer.code:84:27: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’) 84 | return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)]; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’ 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:281:5: note: template argument deduction/substitution failed: answer.code:84:27: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’) 84 | return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)]; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5775:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)’ 5775 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5775:5: note: template argument deduction/substitution failed: answer.code:84:27: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘int’ 84 | return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)]; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5785:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)’ 5785 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5785:5: note: template argument deduction/substitution failed: answer.code:84:27: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘int’ 84 | return results[min(next_round[0] == china_strength ? 0 : 1, (int)results.size() - 1)]; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ At global scope: cc1plus: error: ‘::main’ must return ‘int’