No Rules Rules

쿼드트리 (feat. 백준, 1992번) 본문

생활/코테

쿼드트리 (feat. 백준, 1992번)

개발하는 완두콩 2022. 8. 14. 21:06
728x90
반응형

쿼드트리
https://www.acmicpc.net/problem/1992

 

1992번: 쿼드트리

첫째 줄에는 영상의 크기를 나타내는 숫자 N 이 주어진다. N 은 언제나 2의 제곱수로 주어지며, 1 ≤ N ≤ 64의 범위를 가진다. 두 번째 줄부터는 길이 N의 문자열이 N개 들어온다. 각 문자열은 0 또

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
using namespace std;
int arr[64][64];
void solution(register int x, register int y, register int n) {
	register int sum = 0;
	for (register int i = 0, j; i < n; ++i)
		for (j = 0; j < n; ++j)
			sum += arr[x + i][y + j];
	if (sum == 0)
		cout << "0";
	else if (sum == n * n)
		cout << "1";
	else
		cout << "(", solution(x, y, n / 2),  solution(x, y + n / 2, n / 2), solution(x + n / 2, y, n / 2), solution(x + n/ 2, y + n / 2, n / 2), cout << ")";
}
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	register int N;
	char tmp;
	cin >> N;
	for (register int i = 0, j; i < N; ++i)
		for (j = 0; j < N; ++j)
			cin >> tmp, arr[i][j] = tmp - '0';
	solution(0, 0, N);
	return 0;
}
// *&)*@*
  1. n * n 의 2차원 배열의 전체 합이 0 또는 n * n이 아니라면 '(' 문자를 출력하고 n / 2 * n / 2의 2차원 배열로 재귀를 수행합니다.
  2. 재귀는 (x,y) (x, y+n/2), (x+n/2, y), (x+n/2, y+n/2) 순서대로 수행합니다.
728x90
반응형

'생활 > 코테' 카테고리의 다른 글

곱셈 (feat. 백준, 1629번)  (0) 2022.08.15
종이의 개수 (feat. 백준, 1780번)  (0) 2022.08.14
색종이 만들기 (feat. 백준, 2630번)  (0) 2022.08.13
AC (feat. 백준, 5430번)  (0) 2022.08.13
회전하는 큐 (feat. 백준, 1021번)  (0) 2022.08.13
Comments