문제풀이/백준
백준 1992 - 쿼드트리
레옹
2021. 10. 9. 01:30
#include <iostream>
using namespace std;
int mapSize;
int map[64][64];
void QuadTree(int x, int y, int line) {
if (line == 1) {
cout << map[x][y];
return;
}
int findOneCount = 0;
for (int X = 0; X < line; X++) {
for (int Y = 0; Y < line; Y++) {
if (map[x + X][y + Y] == 1) {
findOneCount++;
}
}
}
if (findOneCount == line * line) {
cout << '1';
return;
}
if (findOneCount == 0) {
cout << '0';
return;
}
if (findOneCount > 0) {
int addPos = (int)(line * 0.5f);
cout << '(';
QuadTree(x, y, addPos);
QuadTree(x + addPos, y, addPos);
QuadTree(x, y + addPos, addPos);
QuadTree(x + addPos, y + addPos, addPos);
cout << ')';
}
}
int main() {
cin >> mapSize;
for (int y = 0; y < mapSize; y++) {
char arr[64 + 1];
for (int x = 0; x < mapSize; x++) {
cin >> arr[x];
}
for (int i = 0;i < mapSize; i++) {
map[i][y] = arr[i] - 48;
}
}
QuadTree(0, 0, mapSize);
return 0;
}