MLE,求调
查看原帖
MLE,求调
980845
_HappyCoder_楼主2024/12/31 21:52
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
#define int long long

const int N = 3e3;
char Map[N + 5][N + 5];
int n;

void Draw(int n, int x, int y) {
	if (n == 1)
		Map[x][y] = 'X';
	else {
		int row = pow(3, n - 2);
		Draw(n - 1, x, y);
		Draw(n - 1, x, y + 2 * row);
		Draw(n - 1, x + row, y + row);
		Draw(n - 1, x + 2 * row, y);
		Draw(n - 1, x + 2 * row, y + 2 * row);
	}
}

signed main() {
	
	while (n != -1) {
		memset(Map, ' ', sizeof(Map));
		scanf("%lld", &n);
		Draw(n, 1, 1); 
		int row = pow(3, n - 1);
		for (int i = 1; i <= row; i++) {
			for (int j = 1; j <= row; j++)
				cout << Map[i][j];
			printf("\n");
		}
		printf("-\n");
	}
	
	return 0;
}
2024/12/31 21:52
加载中...