-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1401.cpp
77 lines (69 loc) · 1.93 KB
/
1401.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
75
#include <iostream>
#include <cmath>
using namespace std;
int table[512][512];
void paint(int x, int y, int i, int j, int n) {
static int c;
++c;
n = n / 2;
if ((x - j) >= n && (y - i) >= n) {
table[i + n - 1][j + n - 1] = c;
table[i + n][j + n - 1] = c;
table[i + n - 1][j + n] = c;
if (n>1){
paint(j + n - 1, i + n - 1, i, j, n);
paint(j + n, i + n - 1, i, j + n, n);
paint(x, y, i + n, j + n, n);
paint(j + n - 1, i + n, i + n, j, n);
}
} else if ((x - j) >= n && (y - i) < n) {
table[i + n - 1][j + n - 1] = c;
table[i + n][j + n - 1] = c;
table[i + n][j + n] = c;
if (n>1){
paint(j + n - 1, i + n - 1, i, j, n);
paint(x, y, i, j + n, n);
paint(j + n, i + n, i + n, j + n, n);
paint(j + n - 1, i + n, i + n, j, n);
}
} else if ((x - j) < n && (y - i) < n) {
table[i + n - 1][j + n] = c;
table[i + n][j + n - 1] = c;
table[i + n][j + n] = c;
if (n>1){
paint(x, y, i, j, n);
paint(j + n, i + n - 1, i, j + n, n);
paint(j + n, i + n, i + n, j + n, n);
paint(j + n - 1, i + n, i + n, j, n);
}
} else if ((x - j) < n && (y - i) >= n) {
table[i + n - 1][j + n - 1] = c;
table[i + n][j + n] = c;
table[i + n - 1][j + n] = c;
if (n>1){
paint(j + n - 1, i + n - 1, i, j, n);
paint(j + n, i + n - 1, i, j + n, n);
paint(j + n, i + n, i + n, j + n, n);
paint(x, y, i + n, j, n);
}
}
return;
}
int main() {
int n, x, y;
cin >> n >> y >> x;
n = 1 << n;
if ((int) (pow(n, 2) - 1) % 3 != 0) {
cout << -1;
return 0;
}
--x;
--y;
paint(x, y, 0, 0, n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
cout << table[i][j] << " ";
cout << endl;
}
return 0;
}