티스토리 뷰

백준 온라인 저지

190316 BOJ 1992번 쿼드트리

Stolen Moments 2019. 3. 16. 18:28

BOJ 1992 쿼드트리 - 분할 정복


- 분할을 할 때 마다 괄호를 씌워준다.





소스 코드


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
#include <iostream>
#define FOR(i,a,b) for(int i = a; i < b; i++)
using namespace std;
int arr[64][64];
int N;
void div(int x, int y, int n) {
    bool flag = true;
    int st = arr[x][y];
    FOR(i, x, x + n) FOR(j, y, y + n) if (st != arr[i][j]) {
        flag = false;
        break;
    }
    if (flag) {
        cout << st;
        return;
    }
    cout << '(';
    div(x, y, n / 2);
    div(x, y + n / 2, n / 2);
    div(x + n / 2, y, n / 2);
    div(x + n / 2, y + n / 2, n / 2);
    cout << ')';
}
int main() {
    cin >> N;
    FOR(i, 0, N) FOR(j, 0, N) scanf("%1d"&arr[i][j]);
    div(00, N);
}
cs


반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/09   »
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
글 보관함