No Rules Rules

종이의 개수 (feat. 백준, 1780번) 본문

생활/코테

종이의 개수 (feat. 백준, 1780번)

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

종이의 개수
https://www.acmicpc.net/problem/1780

 

1780번: 종이의 개수

N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1 중 하나가 저장되어 있다. 우리는 이 행렬을 다음과 같은 규칙에 따라 적절한 크기로 자르려고 한다. 만약 종이가 모두 같은 수

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <algorithm>
using namespace std;
int ans1, ans2, ans3, arr[2187][2187];
void solution(register int x, register int y, register int n) {
	int tmp = 10, count = 0;
	for (register int i = 0, j; i < n; ++i)
		for (j = 0; j < n; ++j)
			if (tmp == 10)
				tmp = arr[x + i][y + j], ++count;
			else
				if (tmp == arr[x + i][y + j])
					++count;
				else
					break;
	if (tmp == -1 && count == n * n)
		++ans1;
	else if (tmp == 0 && count == n * n)
		++ans2;
	else if (tmp == 1 && count == n * n)
		++ans3;
	else {
		solution(x, y, n / 3), solution(x + n / 3, y, n / 3), solution(x + 2 * n / 3, y, n / 3);
		solution(x, y + n / 3, n / 3), solution(x + n / 3, y + n / 3, n / 3), solution(x + 2 * n / 3, y + n / 3, n / 3);
		solution(x, y + 2 * n / 3, n / 3), solution(x + n / 3, y + 2 * n / 3, n / 3), solution(x + 2 * n / 3, y + 2 * n / 3, n / 3);
	}
}
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	register int N;
	cin >> N;
	for (register int i = 0, j; i < N; ++i)
		for (j = 0; j < N; ++j)
			cin >> arr[i][j];
	ans1 = ans2 = ans3 = 0;
	solution(0, 0, N);
	cout << ans1 << "\n" << ans2 << "\n" << ans3;
	return 0;
}
// *&)*@*
  1. 이전 '색종이 만들기' 문제와 유사한 방식입니다.
  2. 다른점이 있다면 2배씩 줄여나가는 것이 아니라 3배씩 줄여나가고, 2개의 정답이 아닌 3개의 정답을 출력하는 차이만 있을 뿐입니다.
  3. 따라서 이전 문제를 먼저 풀어보시길 권장합니다.
 

색종이 만들기 (feat. 백준, 2630번)

색종이 만들기 https://www.acmicpc.net/problem/2630 2630번: 색종이 만들기 첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형..

kim519620.tistory.com

 

728x90
반응형

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

이항 계수 3 (feat. 백준, 11401번)  (0) 2022.08.15
곱셈 (feat. 백준, 1629번)  (0) 2022.08.15
쿼드트리 (feat. 백준, 1992번)  (0) 2022.08.14
색종이 만들기 (feat. 백준, 2630번)  (0) 2022.08.13
AC (feat. 백준, 5430번)  (0) 2022.08.13
Comments