题解
2026-08-24 21:00:21
发布于:江苏
33阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 730;
char g[MAXN][MAXN];
void draw(int x, int y, int n) {
if (n == 1) {
g[x][y] = 'X';
return;
}
int s = 1;
for(int i = 1; i <= n-1; ++i) s *= 3;
int ns = s / 3;
draw(x, y, n-1);
draw(x, y + 2*ns, n-1);
draw(x + ns, y + ns, n-1);
draw(x + 2*ns, y, n-1);
draw(x + 2*ns, y + 2*ns, n-1);
}
int main() {
int T;
cin >> T;
while(T--) {
int n;
cin >> n;
int s = 1;
for(int i = 1; i <= n-1; ++i) s *=3;
memset(g, ' ', sizeof(g));
draw(0,0,n);
for(int i = 0; i < s; ++i) {
for(int j = 0; j < s; ++j) {
cout << g[i][j];
}
cout << endl;
}
cout << "-" << endl;
}
return 0;
}
这里空空如也







有帮助,赞一个