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 size, int 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 == false) break;
}
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, 1, 1);
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
|
'algorithm > BOJ' 카테고리의 다른 글
에라토스테네스의 체 (0) | 2019.06.30 |
---|---|
BOJ 11729번 하노이 탑 이동 순서 (0) | 2019.05.31 |
백준 1992번 : 쿼드트리 - Junnnho (0) | 2019.05.29 |
백준 1011번 : Fly me to the Alpha Centauri - Junnnho (0) | 2019.05.19 |
백준 2529번 : 부등호 Junnnho (0) | 2019.05.17 |