-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
79 lines (68 loc) · 1.35 KB
/
main.c
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
//
// main.c
// BaekJun Algorithm 125(쿼드트리, 1992)
// https://www.acmicpc.net/problem/1992
// Created by hyungwook on 2021/06/24.
//
#include <stdio.h>
#include <stdbool.h>
int n;
int quadtree[64][64];
void set(int x, int y, int pc)
{
int spec = 0;
bool flag = quadtree[x][y];
for(int i = 0; i < pc; i++)
{
for(int j = 0; j < pc; j++)
{
if(flag != quadtree[x + i][y + j])
{
spec = 1;
break;
}
}
}
if(spec == 0)
{
if(flag == false)
{
printf("0");
return;
}
else
{
printf("1");
return;
}
}
printf("(");
set(x, y, pc / 2);
set(x, y + pc / 2, pc / 2);
set(x + pc / 2, y, pc / 2);
set(x + pc / 2, y + pc / 2, pc / 2);
printf(")");
}
int main(int argc, const char * argv[]) {
// insert code here...
char temp[65][65];
scanf("%d", &n);
getchar();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%c", &temp[i][j]);
}
getchar();
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n ; j++)
{
quadtree[i][j] = temp[i][j] - '0';
}
}
set(0, 0, n);
return 0;
}