BOJ : https://www.acmicpc.net/problem/1992

github : https://github.com/junho0956/Algorithm/blob/master/1992/1992/%EC%86%8C%EC%8A%A4.cpp

 

이전에 풀었던 BOJ 1780번 종이의 개수와 같은 문제이다.

/2 씩 해가면서 분할하여 확인하면된다.

 

더보기
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
39
40
#include <cstdio>
using namespace std;
#pragma warning(disable:4996)
int arr[64][64];
 
void quadTree(int N, int y, int x) {
    bool test = true;
    for (int i = y; i < y + N; i++) {
        for (int k = x; k < x + N; k++) {
            if (arr[i][k] != arr[y][x]) {
                test = false;
                break;
            }
        }
        if (!test) break;
    }
 
    if (test) printf("%d",arr[y][x]);
    else {
        printf("(");
        int div = N / 2;
        for (int i = 0; i < 2; i++) {
            for (int k = 0; k < 2; k++) {
                quadTree(div, y + i * div, x + k*div);
            }
        }
        printf(")");
    }
}
 
int main() {
    int N; scanf("%d",&N);
 
    for (int i = 0; i < N; i++)
        for (int k = 0; k < N; k++)
            scanf("%1d"&arr[i][k]);
 
    quadTree(N, 00);
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 10090번 Counting Inversions  (0) 2020.01.17
BOJ 1517번 버블 소트  (0) 2020.01.17
BOJ 1780번 종이의 개수  (0) 2020.01.17
BOJ 11728번 배열 합치기  (0) 2020.01.17
BOJ 11662번 민호와 강호  (0) 2020.01.16

+ Recent posts