
풀이
문제를 보면 알 수 있듯이 분할정복 관련 문제이다.
#include <iostream>
using namespace std;
#define MAX 128
int n;
int cntWhite = 0, cntBlue = 0;
int map[MAX][MAX];
void DevideAndConquer(int x, int y, int size) {
int color = map[x][y];
for (int i = x; i < x + size; i++) {
for (int j = y; j < y + size; j++) {
if (color != map[i][j]){
DevideAndConquer(x, y, size / 2);
DevideAndConquer(x, y + size / 2, size / 2);
DevideAndConquer(x + size / 2, y, size / 2);
DevideAndConquer(x + size / 2, y + size / 2, size / 2);
return;
}
}
}
if (color)
cntBlue++;
else
cntWhite++;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> map[i][j];
DevideAndConquer(0, 0, n);
cout << cntWhite << "\n" << cntBlue;
return 0;
}
'백준 > 기타' 카테고리의 다른 글
[백준/C++] 18110번: solved.ac (0) | 2023.06.28 |
---|---|
[백준/C++] 1780번: 종이의 개수 (0) | 2023.05.22 |
[백준/C++] 1074번: Z (0) | 2023.05.22 |
[백준/C++] 1992번: 쿼드트리 (0) | 2023.05.22 |
[백준/C++] 2667번 : 단지번호붙이기 (1) | 2023.05.18 |