Search

칸토어 집합

주차
0
문제번호
4779
언어
C++
티어
실버
유형
문자열
분할 정복
재귀
nj_Blog
nj_상태
이해도
풀이
사람
이해도 2
13 more properties

Memo

로직 설명

3등분 하여 왼쪽부분과 오른쪽 부분이 이전 길이에서의 로직과 동일한 로직이 적용된다는 점에서 분할 정복을 생각해낼 수 있었습니다.

Code

제출 날짜

@4/29/2021

메모리

2200 KB

시간

44 ms
#include <iostream> #include <cmath> #define endl "\n" void io_faster() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); } void recursion(int n) { if (n == 1) { std::cout << "-"; return; } recursion(n / 3); for (int i = 0 ; i < n / 3 ; i++) std::cout << " "; recursion(n / 3); } void solve(int N) { recursion(std::pow(3, N)); } int main() { int N; while (std::cin >> N) { solve(N); std::cout << endl; } return (0); }
C++
복사