BOJ : https://www.acmicpc.net/problem/1780
github : https://github.com/junho0956/Algorithm/blob/master/1780/1780/%EC%86%8C%EC%8A%A4.cpp
그냥 반복문으로 전체를 훑어도 되지만
문제의 분류가 분할정복이여서 요구하는대로 구현하였다.
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
46
47
|
#include <iostream>
using namespace std;
int N;
int arr[2187][2187]; // 3^7
int counter[3]; // -1 0 1
void paper_count(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) {
if (arr[y][x] == -1) counter[2]++;
else counter[arr[y][x]]++;
}
else {
int div = n / 3;
for (int i = 0; i < 3; i++) {
for (int k = 0; k < 3; k++) {
paper_count(div, y + i * div, x + k * div);
}
}
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
for (int k = 0; k < N; k++) {
cin >> arr[i][k];
}
}
paper_count(N, 0, 0);
cout << counter[2] << '\n' << counter[0] << '\n' << counter[1];
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 1517번 버블 소트 (0) | 2020.01.17 |
---|---|
BOJ 1992번 쿼드트리 (0) | 2020.01.17 |
BOJ 11728번 배열 합치기 (0) | 2020.01.17 |
BOJ 11662번 민호와 강호 (0) | 2020.01.16 |
BOJ 10816번 숫자 카드2 (0) | 2020.01.16 |