-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path742.cpp
More file actions
70 lines (62 loc) · 1.38 KB
/
742.cpp
File metadata and controls
70 lines (62 loc) · 1.38 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
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 66107
* Submitted at: 2018-10-12 16:12:55
*
* User ID: 539
* Username: 55211931
* Problem ID: 742
* Problem Name: Simple Quadtree
*/
#include <iostream>
#include <cmath>
using namespace std;
int calculate(char **array, int rowSt, int rowEnd, int colSt, int colEnd)
{
if (rowEnd == rowSt)
{
return 1;
}
else
{
bool same = true;
char a = array[rowSt][colSt];
for (int i = colSt;i <= colEnd;i++)
{
for (int j = rowSt;j <= rowEnd;j++)
{
if (a != array[j][i])
{
same = false;
}
}
}
if (same == true)
{
return 1;
}
else
{
return 1 + calculate(array, rowSt, (rowSt + rowEnd) / 2, colSt, (colSt + colEnd) / 2) + calculate(array, rowSt, (rowSt + rowEnd) / 2, (colSt + colEnd) / 2 + 1, colEnd) + calculate(array, ((rowSt + rowEnd) / 2) + 1, rowEnd, colSt, (colSt + colEnd) / 2) + calculate(array, (rowSt + rowEnd) / 2 + 1, rowEnd, (colSt + colEnd) / 2 + 1, colEnd);
}
}
}
int main()
{
int k, n;
while (cin >> k)
{
n = pow(2, k);
char**num = new char*[n];
for (int i = 0;i < n;i++)
{
num[i] = new char[n];
}
for (int i = 0;i < n;i++)
{
cin >> num[i];
}
cout << calculate(num, 0, n - 1, 0, n - 1) << endl;
}
return 0;
}