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

57 lines
1.5 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 8//运行结果正确但是N不能太大不然一个屏幕占不下
//开一个二维数组
int a[101][101] = {0};
void table() {
int i, j, t, n = 2, temp;
//因为前4个格子已经填好所以不必循环到t==2。迭代处理依次处理2^2, …, 2^k个选手比赛日程
for (t = 4; t <= N; t *= 2) {
temp = n;
n *= 2; //第一次进来时n=2每执行一次循环n增大一倍
//填左下角元素(构建变量的增量值然后增加n后复制到左下角)
for (i = temp + 1; i <= n; i++) {
for (j = 1; j <= temp; j++) {
a[i][j] = a[i - temp][j] + temp;
}
}
//填右上角元素(右上角是从左下角拷贝过来的)
for (i = 1; i <= temp; i++) {
for (j = temp + 1; j <= n; j++) {
a[i][j] = a[i + temp][j - temp];
}
}
//填右下角元素(直接从左上角复制过来)
for (i = temp + 1; i <= n; i++) {
for (j = temp + 1; j <= n; j++) {
a[i][j] = a[i - temp][j - temp];
}
}
}
}
int main() {
int i, j;
a[1][1] = 1;
a[1][2] = 2;
a[2][1] = 2;
a[2][2] = 1;
//主函数
table();
//输出
for (i = 1; i <= N; i++) {
for (j = 1; j <= N; j++)
cout << a[i][j] << "\t";
cout << endl;
}
return 0;
}