-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path742.cpp
More file actions
77 lines (67 loc) · 1.24 KB
/
Copy path742.cpp
File metadata and controls
77 lines (67 loc) · 1.24 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
#include<iostream>
#include<string>
using namespace std;
bool** map;
bool check(int x, int y, int range) {
if (map[x][y]) {
bool b = true;
for (int i = x; i < x + range; i++) {
for (int j = y; j < y + range; j++) {
b = b & map[i][j];
if (!b) {
return false;
}
}
}
}
else {
bool b = false;
for (int i = x; i < x + range; i++) {
for (int j = y; j < y + range; j++) {
b = b | map[i][j];
if (b) {
return false;
}
}
}
}
return true;
}
int quad(int x, int y, int range) {
int count = 1;
if (range == 1) {
return count;
}
if (!check(x, y, range)) {
count += quad(x, y, range / 2);
count += quad(x + range / 2, y, range / 2);
count += quad(x, y + range / 2, range / 2);
count += quad(x + range / 2, y + range / 2, range / 2);
}
return count;
}
int main() {
int n;
while (cin >> n) {
n = 1 << n;
map = new bool*[n];
for (int i = 0; i < n; i++) {
map[i] = new bool[n];
}
for (int i = 0; i < n; i++) {
string s = "";
while (s == "" || s == "\n") {
cin >> s;
}
for (int j = 0; j < n; j++) {
map[i][j] = (s[j] == '1') ? 1 : 0;
}
}
cout << quad(0, 0, n) << endl;
for (int i = 0; i < n; i++) {
delete[] map[i];
}
delete[] map;
}
return 0;
}