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

 

3^ 형태로 분할되는 형태의 문제입니다.

현재 분할된 지점을 체크해서 -1,0,1 에 대한 값을 확인해주시고 재분할시 조건에 맞게 분할해주시면 됩니다.

 

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
41
42
43
44
45
#include <iostream>
using namespace std;
 
int p[2188][2188];
int arr[3];
 
void move(int sizeint y, int x) {
 
    bool check = true;
    int start = p[y][x];
 
    for (int i = y; i < y + size; i++) {
        for (int j = x; j < x + size; j++) {
            if (start != p[i][j]) {
                check = false;
                break;
            }
        }
        if (check == falsebreak;
    }
 
    if (check == true) {
        if (start == -1) arr[0]++;
        else if (start == 0) arr[1]++;
        else arr[2]++;
    }
    else {
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                move(size / 3, y + (i*size/3), x + (j*size/3));
    }
 
}
 
int main() {
    int N;
    cin >> N;
 
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            cin >> p[i][j];
 
    move(N, 11);
    cout << arr[0<< '\n' << arr[1<< '\n' << arr[2];
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter

+ Recent posts