문제) 백준 - 분할 정복 - 칸토어 집합
https://www.acmicpc.net/problem/4779
4779번: 칸토어 집합
칸토어 집합은 0과 1사이의 실수로 이루어진 집합으로, 구간 [0, 1]에서 시작해서 각 구간을 3등분하여 가운데 구간을 반복적으로 제외하는 방식으로 만든다. 전체 집합이 유한이라고 가정하고,
www.acmicpc.net
큰 문제를 작은 문제로 쪼갤 수 있는 분할 정복 문제입니다. n이 0일 때 "-"를 출력하고, 0보다 클 경우 3 등분으로 쪼개어 작은 문제로 해결합니다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void solve(int n){ | |
if(n == 0){ | |
cout << "-"; | |
return; | |
} | |
solve(n - 1); | |
for(int i = 0; i < (int)pow(3, n - 1); ++i) | |
cout << " "; | |
solve(n - 1); | |
} |
Full Code)
GitHub - Chocochip101/BOJ_Solution: BOJ Solutions
BOJ Solutions. Contribute to Chocochip101/BOJ_Solution development by creating an account on GitHub.
github.com
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 13418번 - 학교 탐방하기 (C++) 문제 및 풀이 (0) | 2022.02.27 |
---|---|
[백준] 18243번 - Small World Network (C++) 문제 및 풀이 (0) | 2022.02.27 |
[백준] 14400번 - 편의점 2 (C++) 문제 및 풀이 (0) | 2022.02.26 |
[백준] 10988번 - 팰린드롬인지 확인하기 (Python) 문제 및 풀이 (0) | 2022.02.25 |
[백준] 21758번 - 꿀 따기 (C++) 문제 및 풀이 (0) | 2022.02.24 |
댓글