Repository navigation
Expand file tree
/
Copy patha62_q1a_recur.cpp
More file actions
66 lines (58 loc) · 1.89 KB
/
Copy patha62_q1a_recur.cpp
File metadata and controls
66 lines (58 loc) · 1.89 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
// #include <bits/stdc++.h>
// using namespace std;
// void recur(vector<vector<int>> &v, int c1, int c2, int r1, int r2, int a, int b);
// int main() {
// std::ios_base::sync_with_stdio(false);std::cin.tie(0);
// int a, b;std::cin >> a >> b;
// vector<vector<int>> v;
// //1 << a = 2**a
// v.resize(1 << a);
// for (auto &e: v) {
// e.resize(1 << a);
// }
// recur(v, 0, 1 << a, 0, 1 << a, a, b);
// for (int i = 0; i < 1 << a; i++) {
// for (int j = 0; j < 1 << a; j++) {
// std::cout << v[i][j] << " ";
// }
// std::cout << "\n";
// }
// return 0;
// }
// void recur(vector<vector<int>> &v, int c1, int c2, int r1, int r2, int a, int b) {
// if (a == 0) {
// v[r1][c1] = b;
// return;
// }
// recur(v, c1, c1 + (1 << (a-1)), r1, r1 + (1 << (a-1)), a-1, b);
// recur(v, c1 + (1 << (a-1)), c2, r1, r1 + (1 << (a-1)), a-1, b-1);
// recur(v, c1, c1 + (1 << (a-1)), r1 + (1 << (a-1)), r2, a-1, b+1);
// recur(v, c1 + (1 << (a-1)), c2, r1 + (1 << (a-1)), r2, a-1, b);
// }
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v;
void dc(int r1, int r2, int c1, int c2, int a, int b) {
if (a == 0) {
v[r1][c1] = b;
return;
}
dc(r1, r1 + (r2 - r1)/2, c1, c1 + (c2 - c1)/2, a-1, b);
dc(r1, r1 + (r2 - r1)/2, c1 + (c2 - c1 + 1)/2, c2, a-1, b-1);
dc(r1 + (r2 - r1 + 1)/2, r2, c1, c1 + (c2 - c1)/2, a-1, b+1);
dc(r1 + (r2 - r1 + 1)/2, r2, c1 + (c2 - c1 + 1)/2, c2, a-1, b);
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int a, b;std::cin >> a >> b;
v.resize((1 << a) + 1);
for (auto &e: v) {
e.resize((1 << a) + 1);
}
dc(1, 1 << a, 1, 1 << a, a, b);
for (int i = 1; i <= (1 << a); i++) {
for (int j = 1; j <= (1 << a); j++) std::cout << v[i][j] << " ";
std::cout << "\n";
}
return 0;
}