Files
python/TangDou/LuoGuBook/P1498.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

47 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}