-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1780.cpp
87 lines (81 loc) · 1.49 KB
/
1780.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 1780. 종이의 개수
// 2019.05.18
// 분할 정복
#include<iostream>
using namespace std;
int map[2188][2188];
int num1; // -1의 개수
int num2; // 0의 개수
int num3; // 1의 개수
void Divide(int size, int x, int y)
{
if (size == 1)
{
if (map[x][y] == 1)
{
num3++;
return;
}
else if(map[x][y]==0)
{
num2++;
return;
}
else
{
num1++;
return;
}
}
// 분할된 곳의 좌상단의 값을 저장
int tmp = map[x][y];
for (int i = x; i < x + size; i++)
{
for (int j = y; j < y + size; j++)
{
if (map[i][j] != tmp)
{
// 9개로 분할
Divide(size / 3, x, y);
Divide(size / 3, x, y + size / 3);
Divide(size / 3, x, y + (size / 3)*2);
Divide(size / 3, x + size / 3, y);
Divide(size / 3, x + size / 3, y+(size/3));
Divide(size / 3, x + size / 3, y+(size/3*2));
Divide(size / 3, x + (size / 3*2), y );
Divide(size / 3, x + (size / 3*2), y + (size / 3));
Divide(size / 3, x + (size / 3*2), y + (size / 3*2));
return;
}
}
}
// 모두 같은 숫자일땐 해당 수의 개수 값을 1더한다.
if (tmp == 1)
{
num3++;
}
else if(tmp==0)
{
num2++;
}
else
{
num1++;
}
}
int main()
{
int n;
cin>>n;
int size = n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>map[i][j];
}
}
Divide(n,0,0);
cout<<num1<<endl<<num2<<endl<<num3<<endl;
return 0;
}