Baekjoon
[#2630] 색종이 만들기
강람이
2020. 3. 16. 20:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector<vector<int>> paper(128, vector<int>(128, 0)); //종이
int blueNum = 0;
int whiteNum = 0;
bool isOneColor(int rowStart, int colStart, int rowFinish, int ColFinish) {
//[rowStart][colStart]~[rowFinish][colFinish]가 한 색으로만 되어있는지 확인
bool ret = true;
int color = paper[rowStart][colStart]; //한색으로 되어있다면 어떤색인지
int size = rowFinish - rowStart + 1;
for (int i = rowStart; i <= rowFinish; i++) {
for (int j = colStart; j <= ColFinish; j++) {
if (color != paper[i][j]) {
//다른색으로 되어있다면 다시 네개로 나눠서 재귀
isOneColor(rowStart, colStart, rowStart + size/2 - 1, colStart + size/2 - 1);
isOneColor(rowStart, colStart + size / 2, rowStart + size / 2 - 1, colStart + size - 1);
isOneColor(rowStart + size / 2, colStart, rowStart + size - 1, colStart + size / 2 - 1);
isOneColor(rowStart + size / 2, colStart + size / 2, rowStart + size - 1, colStart + size - 1);
return false;
}
}
}
if (color == 0)
++whiteNum;
else if (color == 1)
++blueNum;
return ret;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &paper[i][j]);
}
}
isOneColor(0, 0, n - 1, n - 1);
cout << whiteNum << "\n";
cout << blueNum << "\n";
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |