예전에 풀어봤던 문제인데 해맸다.
0,1,-1의 개수를 세어 주고 n*n개 인지 비교하고 아니면 분할하는 방식으로 했는데 왜인지 계속 정답이 안나왔다.
재귀가 잘못된건지 뭐가 잘못된건지 못찾아서 다른 방식으로 했다.
하나라도 다른 것이 있으면 분할하고 아니면 카운트 해주었다.
#include<iostream>
#include<cmath>
using namespace std;
int nn,temp;
int num[2200][2200];
int ans[3];
int check;
void division(int x, int y, int n)
{
check = num[x][y];
for (int i = x; i < x + n; i++)
for (int j = y; j < y + n; j++)
{
if (num[i][j] != num[x][y])
{
division(x, y, n/3);
division(x + n*1/3, y, n/3);
division(x + n*2/3, y, n/3);
division(x, y + n * 1 / 3, n / 3);
division(x + n * 1 / 3, y + n / 3, n / 3);
division(x + n * 2 / 3,y+ n / 3, n / 3);
division(x, y + n * 2 / 3, n / 3);
division(x + n * 1 / 3, y + n * 2 / 3, n / 3);
division(x + n * 2 / 3, y + n * 2 / 3, n / 3);
return;
}
}
ans[num[x][y] + 1]++;
return;
}
int main()
{
cin >> nn;
for (int i = 0; i < nn; i++)
for (int j = 0; j < nn; j++)
cin >> num[i][j];
division(0,0,nn);
cout << ans[0] << "\n" << ans[1] << "\n" << ans[2];
}
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 1759 암호만들기 c++ (0) | 2022.07.08 |
---|---|
[백준] 2503 숫자야구 c++ (0) | 2022.07.08 |
[백준] 2839설탕배달 c++ (0) | 2022.05.28 |
[백준 ] 2042 구간합 구하기 C++ (0) | 2022.05.22 |
[백준] 1992 쿼드트리 c++ (0) | 2022.05.14 |