Files
python/TangDou/FenZhi/RiChengBiao3.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

64 lines
2.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
#define N 50
//声明日程表安排函数
void GameTable(int k, int array[N][N]);
//输出二维数组
void Print(int k, int array[N][N]);
int main() {
int k;
int array[N][N];
cout << "****************************************" << endl;
cout << "** 循环赛日程表 **" << endl;
cout << "****************************************" << endl;
cout << "设参赛选手的人数为nn=2^k请输入k 的值:" << endl;
cin >> k;
if (k != 0) {
GameTable(k, array);
Print(k, array);
} else
cout << "您输入的数据有误,请重新输入!" << endl;
return 0;
}
//数组下标从1开始
void GameTable(int k, int array[N][N]) {
int i, j, s, t;
//个数
int n = 1 << k;
//求总人数
for (i = 1; i <= n; i++)
array[1][i] = i; //第一行排1-8
int m = 1; //用来控制每一次填表时i行j列的起始填充位置
//s指对称赋值的总循环次数即分成几大步进行制作日程表
for (s = 1; s <= k; s++) {
n = n / 2;
for (t = 1; t <= n; t++) //t指明内部对称赋值的循环次数
for (i = m + 1; i <= 2 * m; i++)
for (j = m + 1; j <= 2 * m; j++) {
array[i][j + (t - 1) * m * 2] = array[i - m][j + (t - 1) * m * 2 - m]; //右上角等于左上角的值
array[i][j + (t - 1) * m * 2 - m] = array[i - m][j + (t - 1) * m * 2]; //左下角等于右上角的值
}
m *= 2;
}
}
//输出二维数组
void Print(int k, int array[N][N]) {
int i, j;
int num = pow(2, k);
cout << num << "人的循环赛日程表如下" << endl;
//输出二维数组
for (i = 1; i <= num; i++) {
for (j = 1; j <= num; j++) {
cout << array[i][j] << "\t";
}
cout << endl;
}
cout.flush();
}