题目链接: https://www.luogu.com.cn/problem/P1498
思路: 分治
#include <bits/stdc++.h>
using namespace std;
char a[2000][2000];
int h = 2, w = 4;//h为高 w宽
int main() {
int n;
cin >> n;
memset(a, ' ', sizeof(a));//全部清空
a[1][2] = a[2][1] = '/';
a[2][2] = a[2][3] = '_';
a[1][3] = a[2][4] = '\\';
for (int k = 1; k < n; k++) {
//向下和向右
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
a[i + h][j] = a[i + h][j + w] = a[i][j];
a[i][j] = ' ';//上面置空
}
}
//向上
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
a[i][j + w / 2] = a[i + h][j];
}
}
//倍增
h *= 2, w *= 2;
}
//将结果输出
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cout << a[i][j];
}
cout << "\n";
}
return 0;
}