-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1992.cpp
74 lines (71 loc) · 1.13 KB
/
1992.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
// 1992. 쿼드트리
// 2019.05.19
// 분할 정복
#include<iostream>
#include<string>
using namespace std;
string ans = "";
int map[65][65];
// 4개로 분할하는 함수
void Divide(int size, int x, int y)
{
if (size == 1)
{
if (map[x][y] == 1)
{
ans+='1';
return;
}
else
{
ans+='0';
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)
{
ans+='(';
// 4개로 분할
Divide(size / 2, x, y);
Divide(size / 2, x, y + size / 2);
Divide(size / 2, x + size / 2, y);
Divide(size / 2, x + size / 2, y + size / 2);
ans+=')';
return;
}
}
}
// 모두 같은 숫자일땐 값을 추가해줌
if (tmp == 1)
{
ans+='1';
}
else
{
ans+='0';
}
}
int main()
{
int n;
cin>>n;
int size = n;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
for(int j=0;j<n;j++)
{
map[i][j]=s[j]-'0';
}
}
Divide(n,0,0);
cout<<ans<<endl;
return 0;
}