Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
83026 sh25_shenpy 比赛安排 C++ 解答错误 1 MS 256 KB 2666 2026-01-19 20:35:25

Tests(0/3):


#include <iostream> #include <vector> #include <iomanip> using namespace std; const int MAX_TEAM = 64; // 2^6=64,满足n<=6的要求 int schedule[MAX_TEAM][MAX_TEAM]; // schedule[i][j]表示第i天,第j支球队的对手 // 分治生成比赛安排 // team_num: 当前处理的球队数量(2^k) // start: 起始球队编号 // day_offset: 天数偏移量(用于递归时定位天数) void generateSchedule(int team_num, int start, int day_offset) { if (team_num == 1) return; // 只有1支球队,无需比赛 int half = team_num / 2; // 递归处理前半组和后半组的内部比赛 generateSchedule(half, start, day_offset); generateSchedule(half, start + half, day_offset); // 处理跨组比赛(前半组 vs 后半组) for (int i = 0; i < half; ++i) { // 遍历前半组的天数 for (int j = 0; j < half; ++j) { // 遍历前半组的球队 // 第day_offset + half + i 天,start+j 的对手是 start+half+j+i int day = day_offset + half + i; int team1 = start + j; int team2 = start + half + (j + i) % half; schedule[day][team1] = team2; schedule[day][team2] = team1; } } } int main() { int n; cin >> n; int total_team = 1 << n; // 2^n支球队 int total_day = total_team - 1; // 总天数2^n -1 // 初始化赛程表 for (int i = 1; i <= total_day; ++i) { for (int j = 1; j <= total_team; ++j) { schedule[i][j] = 0; } } // 生成赛程 generateSchedule(total_team, 1, 0); // 按格式输出每天的比赛安排 for (int day = 1; day <= total_day; ++day) { cout << "<" << day << ">"; vector<pair<int, int>> matches; // 存储当天的比赛对 // 标记已安排比赛的球队,避免重复 vector<bool> used(total_team + 1, false); for (int team = 1; team <= total_team; ++team) { if (!used[team]) { int opponent = schedule[day][team]; if (opponent == 0) opponent = team; // 理论上不会出现 matches.push_back({team, opponent}); used[team] = true; used[opponent] = true; } } // 输出比赛对,按球队编号升序,格式为a-b for (int i = 0; i < matches.size(); ++i) { if (i > 0) cout << ","; cout << matches[i].first << "-" << matches[i].second; } cout << endl; } return 0; }


测评信息: