문제 : https://www.acmicpc.net/problem/1780
[ 알고리즘풀이 ]
처음엔 (0, 0)에서 시작해서 N x N 배열을 확인합니다. 이때, N x N 배열의 값이 다 같다면 그 값에 해당하는 count 를 올려주고, 아니라면 N x N 배열을 9개로 분할해 다시 재귀적으로 함수를 호출합니다.
#include<iostream>
using namespace std;
int N, map[2187][2187] = {}, ans[3] = {};
void countPaper(int r, int c, int s) {
int temp= map[r][c];
bool check = false;
for (int i = 0; i < s; i++)
for (int j = 0; j < s; j++)
if (map[r + i][c + j] != temp) {
check = true;
i = s, j = s;
}
if (!check)
ans[temp + 1]++;
else {
int k = s / 3;
countPaper(r, c, k);
countPaper(r, c + k, k);
countPaper(r , c + 2*k, k);
countPaper(r + k, c, k);
countPaper(r + k, c + k, k);
countPaper(r + k, c + 2 * k, k);
countPaper(r + 2*k, c, k);
countPaper(r + 2 *k, c + k, k);
countPaper(r + 2*k, c + 2 * k, k);
}
return;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> map[i][j];
countPaper(0, 0, N);
cout << ans[0] << '\n' << ans[1] << '\n' << ans[2];
return 0;
}
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 2630 : 색종이 만들기 - travelbeeee (0) | 2020.01.29 |
---|---|
[BOJ] 17198 : Bucket Brigade - travelbeeee (0) | 2020.01.29 |
[BOJ] 1992 : 쿼드트리 - travelbeeee (0) | 2020.01.29 |
[BOJ] 2437 : 저울 - travelbeeee (0) | 2020.01.28 |
[BOJ] 2436 : 공약수 - travelbeeee (0) | 2020.01.28 |