-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbitmap.cpp
More file actions
126 lines (111 loc) · 1.81 KB
/
bitmap.cpp
File metadata and controls
126 lines (111 loc) · 1.81 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <bits/stdc++.h>
using namespace std;
#define MAX 200
#define D -1
typedef int matrix[MAX][MAX];
int current_col;
#define MAX_COL_LINE 50
int check(matrix m, int l1, int c1, int l2, int c2)
{
int ans = D;
for (int i = l1; i < l2; ++i)
{
for (int j = c1; j < c2; ++j)
{
if ( (ans == 1 || ans == D ) && m[i][j] == 1 )
{
ans = 1;
}
else if ( (ans == 0 || ans == D ) && m[i][j] == 0 )
{
ans = 0;
}
else
{
return D;
}
}
}
return ans;
}
/*
l1 = inclusivo
c1 = inclusivo
l2 = exclusivo
c2 = exclusivo
*/
void dq(matrix m, int l1, int c1, int l2, int c2)
{
if (l1 == l2 || c1 == c2)
{
return;
}
int ans = check(m, l1, c1, l2, c2);
if (ans != D)
{
if ( current_col == MAX_COL_LINE )
{
current_col = 0;
printf("\n");
}
printf("%d", ans);
++current_col;
return;
}
else
{
if ( current_col == MAX_COL_LINE )
{
current_col = 0;
printf("\n");
}
printf("D");
++current_col;
if (l2 - l1 == 1 && c2-c1 ==1)
{
return;
}
int mid_col = ceil((c1 + c2) / 2.0);
int mid_lin = ceil((l1 + l2) / 2.0);
dq(m, l1, c1, mid_lin, mid_col); // top left
dq(m, l1, mid_col, mid_lin, c2); // top right
dq(m, mid_lin, c1, l2, mid_col); // bottom left
dq(m, mid_lin, mid_col, l2, c2); // bottom right
}
}
void print_m(matrix m, int lin, int col)
{
printf("\n");
for (int i = 0; i < lin; ++i)
{
for (int j = 0; j < col; ++j)
{
printf("%d", m[i][j]);
}
printf("\n");
}
}
int main()
{
int tc, lin, col;
string line;
matrix m;
scanf("%d", &tc);
while (tc--)
{
scanf("%d%d\n", &lin, &col);
for (int i = 0; i < lin; ++i)
{
getline(cin, line);
for (int j = 0; j < col; ++j)
{
m[i][j] = line[j] - '0';
}
}
// print_m(m, lin, col);
current_col = 0;
dq(m, 0, 0, lin, col);
printf("\n");
}
return 0;
}