[ ALGORITHM ]/[ 백 준 ]

[BAEKJOON] 2630번 : 색종이 만들기

HiStar__ 2020. 8. 1. 17:09

문 제

 

소 스  코 드

#include <iostream>
#include <vector>

constexpr int BLUE{ 1 };
constexpr int WHITE{ 0 };

void BlueAndWhite();
void ExamineColor(int **, const int&, const int&, const int&, int&, int &);
bool CompareColor(int **, const int&, const int&, const int&, int&, int &);

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cout.tie(NULL);
	std::cin.tie(NULL);

	BlueAndWhite();

	return 0;
}

void BlueAndWhite() {
	int N;
	std::cin >> N;
	int **Confetti{ new int*[N] };
	for (int i = 0; i < N; ++i) Confetti[i] = new int[N];

	int num;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			std::cin >> num;
			Confetti[j][i] = num;
		}
	}
	
	int blue{ 0 }, white{ 0 };

	ExamineColor(Confetti, N, 0, 0, blue, white);

	std::cout << white << '\n' << blue << '\n';

	for (int i = 0; i < N; ++i) delete[] Confetti[i];
	delete[] Confetti;
}

void ExamineColor(int ** arr, const int& n, const int& x, const int& y, int& blue, int & white) {
	if (CompareColor(arr, n, x, y, blue, white)) return;
	else {
		int number{ n / 2 };
		
		ExamineColor(arr, number, x, y, blue, white);
		ExamineColor(arr, number, x + number, y, blue, white);
		ExamineColor(arr, number, x, y + number, blue, white);
		ExamineColor(arr, number, x + number, y + number, blue, white);
	}
}

bool CompareColor(int ** arr, const int& n, const int& x, const int& y, int& blue, int & white) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (arr[y][x] != arr[j + y][i + x]) return false;
		}
	}
	if (BLUE == arr[y][x])			++blue;
	else if (WHITE == arr[y][x])	++white;

	return true;
}

 

풀 이

 

위의 그림을 반복한다.

 

출 력 값

 

 

문 제  출 처

문제 링크 : [ BAEKJOON ] :  https://www.acmicpc.net/problem/2630

 

2630번: 색종이 만들기

첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.

www.acmicpc.net