设有n=2k个运动员要进行网球循环赛。现要设计一个满足以下要求的比赛日程表:c语言
时间: 2024-04-06 11:18:35 浏览: 152
基于C++实现循环赛日程表(算法设计与分析)【100011784】
#include <stdio.h>
#define MAXN 100
int n, k, round, match[MAXN][MAXN];
void schedule() {
int i, j, p;
for (round = 1; round < n; round++) {
if (round % 2 == 1)
match[round][1] = n;
else
match[round][1] = n - 1;
p = (round - 1) / 2;
for (i = 2; i <= k; i++)
match[round][i] = (n + i - p - 2) % (n - 1);
for (i = k + 1; i < n; i++)
match[round][i] = (match[round][i - k] + k - 1) % (n - 1);
}
}
int main() {
int i, j;
printf("请输入运动员人数n:");
scanf("%d", &n);
k = n / 2;
schedule();
printf("比赛日程表如下:\n");
for (i = 1; i < n; i++) {
printf("第%d轮:", i);
for (j = 1; j <= n / 2; j++)
printf("%d vs %d ", j, match[i][j]);
printf("\n");
}
return 0;
}
阅读全文