본문 바로가기
알고리즘/Divide and Conquer-일반

catoring along 더블릿

by tryotto 2019. 2. 13.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <cmath>
 
using namespace std;
int arr[10000000= { 0 };
 
void cut(int st, int end) {    
    if (st == end)
        return;
 
    int n = end - st + 1;
    n /= 3;
 
    for (int i = st + n; i < st + 2 * n; i++) {
        arr[i] = 0;
    }
 
    cut(st, st + n - 1);
    cut(end-n+1end);
}
 
int main() {
    int n,num;
    scanf("%d"&n);
    num = (int)pow(3, n);
    for (int i = 1; i <= num; i++) {
        arr[i] = 1;
    }
 
    cut(1, num);
 
    for (int i = 1; i <= num; i++) {
        if (arr[i] == 1)
            printf("-");
        else
            printf(" ");
    }
}
cs


'알고리즘 > Divide and Conquer-일반' 카테고리의 다른 글

QuadTree 더블릿  (0) 2019.03.05
색종이 만들기 더블릿  (0) 2019.02.13
1992 쿼드트리  (0) 2019.02.11