-
[2447] 별 찍기 - 10BOJ 2022. 3. 18. 19:50
https://www.acmicpc.net/problem/2447
2447번: 별 찍기 - 10
재귀적인 패턴으로 별을 찍어 보자. N이 3의 거듭제곱(3, 9, 27, ...)이라고 할 때, 크기 N의 패턴은 N×N 정사각형 모양이다. 크기 3의 패턴은 가운데에 공백이 있고, 가운데를 제외한 모든 칸에 별이
www.acmicpc.net
매번 size를 1/3로 줄이고, 구간을 9개로 나누어서 재귀적으로 별을 찍자
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;char ans[6565][6565];int n;void f(int y, int x, int sz, bool flag) {int i, j;if (flag) {for (i = y; i < y + sz; i++)for (j = x; j < x + sz; j++) ans[i][j] = ' ';return;}if (sz == 3) {for (i = y; i < y + 3; i++)for (j = x; j < x + 3; j++) ans[i][j] = '*';ans[y + 1][x + 1] = ' ';return;}int nsz = sz / 3;int ny[3] = {y, y + nsz, y + nsz + nsz};int nx[3] = {x, x + nsz, x + nsz + nsz};for (i = 0; i < 3; i++) {for (j = 0; j < 3; j++) {if (i == 1 && j == 1)f(ny[i], nx[j], nsz, true);elsef(ny[i], nx[j], nsz, false);}}}int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;f(0, 0, n, false);int i, j;for (i = 0; i < n; i++) {for (j = 0; j < n; j++) cout << ans[i][j];cout << '\n';}return 0;}
'BOJ' 카테고리의 다른 글
[2665] 미로만들기 (0) 2022.03.22 [10282] 해킹 (0) 2022.03.22 [14425] 문자열 집합 (0) 2022.03.15 [1445] 일요일 아침의 데이트 (0) 2022.03.13 [2304] 창고 다각형 (0) 2022.03.12