题目描述
题目链接
C++ 代码
#include<bits/stdc++.h>
using namespace std;const int N = 750;
char G[7][N][N];void Copy(char g1[][N], char g2[][N], int r1, int c1, int r2, int c2) {for(int i = r1; i <= r2; i ++)for(int j = c1; j <= c2; j ++)g1[i][j] = g2[i - r1 + 1][j - c1 + 1];
}void Print(char g[][N], int n) {for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {cout << g[i][j];}cout << '\n';}
}void Set(char g[][N], int n) {for(int i = n / 3 + 1; i <= n / 3 * 2; i ++) {for(int j = n / 3 + 1; j <= n / 3 * 2; j ++)g[i][j] = '.';}
}int POW(int x, int y) {int res = 1;for(int i = 1; i <= y; i ++)res = res * x;return res;
}int main() { int n;cin >> n;G[0][1][1] = '#';for(int k = 1; k <= 6; k ++) {int d1 = POW(3, k), d2 = POW(3, k - 1);for(int i = 1; i <= d1; i += d2)for(int j = 1; j <= d1; j += d2)Copy(G[k], G[k - 1], i, j, i + d2 - 1, j + d2 - 1);Set(G[k], d1);}Print(G[n], POW(3, n));return 0;
}