P1498. 南蛮图腾

考点

  • 分治
  • 字符串

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>

using namespace std;

//最大长度为2048,高度为长度的一半
char table[1024][2048];

void init()
{
for (int i = 0; i < 1024; ++i)
for (int j = 0; j < 2048; ++j)
table[i][j] = ' ';
table[1023][0] = '/', table[1023][1] = table[1023][2] = '_', table[1023][3] = '\\';
table[1022][1] = '/', table[1022][2] = '\\';
}

void print(int width, int height)
{
for (int i = 1024 - height; i < 1024; ++i)
{
for (int j = 0; j < width; ++j)
{
cout << table[i][j];
}
cout << endl;
}
}

int main()
{
int n, cnt = 2;
cin >> n;
init();
int width = 4, height = width >> 1;
while (cnt <= n)
{
for (int i = 1024 - height; i < 1024; ++i)
{
for (int j = 0; j < width; ++j)
{
// 向右复制
table[i][j + width] = table[i][j];
// 向上复制
table[i - height][j + height] = table[i][j];
}
}
++cnt, width *= 2, height *= 2;
}
print(width, height);
return 0;
}

思路

划分子问题,每次把图腾向右复制和向上复制即可