浅发一下啦

Papyrus在审判你  •  1个月前


#include <bits/stdc++.h>
using namespace std;

int a[1050][1050] = {0};

void dfs(int sx, int ex, int sy, int ey, int doub) {
	if (doub <= 1) {
		return;
	}

	int halfx = (sx + ex) / 2;
	int halfy = (sy + ey) / 2;
	dfs(halfx + 1, ex, sy, halfy, doub / 2);

	for (int i = sx; i <= halfx; i++) {

		for (int j = halfy + 1; j <= ey; j++) {

			a[i][j] = a[i + (doub / 2)][j - (doub / 2)];
		}
	}

	dfs(sx, halfx, sy, halfy, doub / 2);

	for (int i = halfx + 1; i <= ex; i++) {

		for (int j = halfy + 1; j <= ey; j++) {

			a[i][j] = a[i - (doub / 2)][j - (doub / 2)];
		}
	}
}

int main() {
	int x;
	cin >> x;
	int w = pow(2, x);

	for (int i = 1; i <= w; i++) {

		a[i][1] = i;
	}

	dfs(1, w, 1, w, w);

	for (int i = 1; i <= w; i++) {

		for (int j = 1; j <= w; j++) {

			cout << a[i][j] << " ";
		}

		cout << endl;
	}

	return 0;
}

评论:

请先登录,才能进行评论