递归解法
#include <iostream>
#include <algorithm>
using namespace std;
int Play[50][50];
void solve(int row, int col, int size)
{
if (size == 1)
return;
int half = size / 2;
Play[row + half][col + half] = Play[row][col]; //右下角格子与左上角是相同的
Play[row][col + half] = Play[row + half][col] = Play[row][col]+half;// 右上角和左下角的格子等于左上角格子加上子表格的大小
//递归求解
solve(row, col, half);
solve(row, col + half, half);
solve(row + half, col, half);
solve(row + half, col + half, half);
}
int main()
{
Play[0][0] = 1;
int n;
cin >> n;
solve(0, 0, n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << Play[i][j] << " ";
cout << endl;
}
system("pause");
}