作者:mobiledu2502926527 | 来源:互联网 | 2023-09-24 19:50
算法说明这个算法主要是找规律,对角线块的排列是一样的,直接进行块复制源代码#includeusingnamespacestd;#definemax10000in
- 算法说明
这个算法主要是找规律,对角线块的排列是一样的,直接进行块复制
- 源代码
#include
using namespace std;
#define max 10000
int b[max][max];
void copy(int n);
void tournament(int n);
int main() {
//freopen("CloestPointInput.txt", "r", stdin);
int n; //n支队伍
scanf("%d", &n);
//process
tournament(n); //锦标赛
//output
freopen("tournamentSchedulingOutput.txt", "w", stdout);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
printf("%4d", b[i][j]);
printf("\n");
}
return 0;
}
void copy(int n) {
//通过左下角的块生成其他三个块
int m, i, j;
m = n / 2;
for(i = 1; i <= m; i++)
for(j = 1; j <= m; j++)
{
b[i][j+m] = b[i][j]+m;
b[i+m][j] = b[i][j]+m;
b[i+m][j+m] = b[i][j];
}
}
void tournament(int n){
if (n == 1){
b[1][1] = 1;
return;
}
tournament(n / 2);
copy(n);
}
- 运行结果