P1498 南蛮图腾题解
作者:互联网
用分治很简单. 每次向下复制一下,向右复制一下,再向上复制一下.
/\
/__\
/\ /\
/__\/__\
向下和向右:(顺便把原本的清掉)
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
再向上:
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
#include <bits/stdc++.h>
using namespace std;
//https://www.luogu.com.cn/blog/froggy/solution-p1498
const int N = 3010;//开大点
char a[N][N];
int n;
int h = 2, w = 4;//h是高,w是宽
void init() {
memset(a, ' ', sizeof(a));
a[1][2] = a[2][1] = '/';
a[1][3] = a[2][4] = '\\';
a[2][2] = a[2][3] = '_';
}
int main() {
//初始化
init();
//读入
cin >> n;
//迭代n-1次,因为第一个三角形已经写死了~
for (int i = 1; i < n; i++) {
//向下和向右
for (int j = 1; j <= h; j++) {
for (int k = 1; k <= w; k++) {
a[j + h][k] = a[j + h][k + w] = a[j][k];
a[j][k] = ' ';//把上面的清掉
}
}
//向上
for (int j = 1; j <= h; j++)
for (int k = 1; k <= w; k++)
a[j][k + w / 2] = a[j + h][k];
//双倍扩展
w *= 2, h *= 2;
//刷新完成一次
}
//输出大吉
for (int i = 1; i <= h; i++) { //高度就是行
for (int j = 1; j <= w; j++) //宽度就是列
cout << a[i][j];
cout << endl;
}
return 0;
}
标签:__,int,题解,init,复制,一下,南蛮,P1498,向下 来源: https://www.cnblogs.com/littlehb/p/15033788.html