Recent Posts
Notice
No Rules Rules
색종이 만들기 (feat. 백준, 2630번) 본문
728x90
반응형
색종이 만들기
https://www.acmicpc.net/problem/2630
2630번: 색종이 만들기
첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
using namespace std;
int white, blue, arr[128][128];
void solution(int x, int y, 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 == n * n)
++blue;
else if (sum == 0)
++white;
else
solution(x, y, n / 2), solution(x + n / 2, y, n / 2), solution(x, y + n / 2, n / 2), solution(x + n / 2, y + n / 2, n / 2);
}
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
white = blue = 0;
register int N;
cin >> N;
for (register int i = 0, j; i < N; ++i)
for (j = 0; j < N; ++j)
cin >> arr[i][j];
solution(0, 0, N);
cout << white << "\n" << blue;
return 0;
}
// *&)*@*
문제의 요구사항처럼 색종이의 모든 칸이 같은 색이 아닌 경우, 재귀함수를 다시 호출하면서 N을 반으로 나누는 형태입니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
종이의 개수 (feat. 백준, 1780번) (0) | 2022.08.14 |
---|---|
쿼드트리 (feat. 백준, 1992번) (0) | 2022.08.14 |
AC (feat. 백준, 5430번) (0) | 2022.08.13 |
회전하는 큐 (feat. 백준, 1021번) (0) | 2022.08.13 |
덱 (feat. 백준, 10866번) (0) | 2022.08.13 |
Comments