QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#565960 | #9308. World Cup | chhh31 | WA | 1ms | 3788kb | C++17 | 2.7kb | 2024-09-15 22:43:43 | 2024-09-15 22:43:46 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 模拟淘汰赛,返回中国队的最佳成绩
int knockout_stage(vector<int> &qualified, int china_team) {
// 淘汰赛对阵顺序按照题目中给定的固定赛程
vector<int> round16 = {0, 9, 4, 13, 8, 17, 12, 21, 1, 8, 5, 12, 9, 16, 13, 14};
vector<int> next_round;
// 16强赛
for (int i = 0; i < 16; i += 2) {
int winner = max(qualified[round16[i]], qualified[round16[i + 1]]);
next_round.push_back(winner);
}
// 检查中国队是否晋级
if (find(next_round.begin(), next_round.end(), china_team) == next_round.end()) return 16;
vector<int> quarterfinals;
// 8强赛
for (int i = 0; i < 8; i += 2) {
int winner = max(next_round[i], next_round[i + 1]);
quarterfinals.push_back(winner);
}
// 检查中国队是否晋级
if (find(quarterfinals.begin(), quarterfinals.end(), china_team) == quarterfinals.end()) return 8;
vector<int> semifinals;
// 4强赛
for (int i = 0; i < 4; i += 2) {
int winner = max(quarterfinals[i], quarterfinals[i + 1]);
semifinals.push_back(winner);
}
// 检查中国队是否晋级
if (find(semifinals.begin(), semifinals.end(), china_team) == semifinals.end()) return 4;
// 决赛
int final_winner = max(semifinals[0], semifinals[1]);
if (final_winner == china_team) return 1; // 中国队获得冠军
return 2; // 中国队在决赛中输掉
}
void solve() {
vector<vector<int>> groups(8);
int china_team;
// 读取8组每组4个队伍,并按降序排序
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 4; ++j) {
int team;
cin >> team;
groups[i].push_back(team);
if (i == 0 && j == 0) china_team = team; // 假设第一个队伍是中国队
}
sort(groups[i].rbegin(), groups[i].rend()); // 每组队伍按实力排序
}
vector<int> qualified; // 存储晋级淘汰赛的队伍
// 取每组前两名队伍晋级
for (int i = 0; i < 8; ++i) {
qualified.push_back(groups[i][0]);
qualified.push_back(groups[i][1]);
}
// 如果中国队没有晋级淘汰赛,直接返回32
if (find(qualified.begin(), qualified.end(), china_team) == qualified.end()) {
cout << 32 << endl;
return;
}
// 模拟淘汰赛,输出中国队的最佳成绩
cout << knockout_stage(qualified, china_team) << endl;
}
int main() {
int t;
cin >> t; // 测试用例的数量
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
1 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3520kb
input:
32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 4 1 2 3 5 6 7 8 9 10 11 12 13 14 15 ...
output:
32 32 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 8 8 8 8 8 8 8 8 4 2 2 2 2 1
result:
wrong answer 7th numbers differ - expected: '8', found: '16'