This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiling.cpp
88 lines (83 loc) · 2.13 KB
/
tiling.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
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
inline unsigned char quad(int x1, int x2, int y1, int y2, int x, int y)
{
bool left = x <= (x1 + x2) / 2;
bool top = y <= (y1 + y2) / 2;
if (!left && top)
return 1;
else if (left && top)
return 2;
else if (left && !top)
return 3;
else
return 4;
}
int orient[] = {0, 1, 0, 2, 3};
vector<tuple<int, int, int>> cmd;
void solve(int l, int x1, int x2, int y1, int y2, int x, int y)
{
int q = quad(x1, x2, y1, y2, x, y);
if (l == 2)
{
cmd.emplace_back(orient[q], x1, y1);
return;
}
int xm = (x1 + x2) / 2;
int ym = (y1 + y2) / 2;
int l2 = l / 2;
switch (q)
{
case 1:
{
solve(l2, xm + 1, x2, y1, ym, x, y);
solve(l2, x1, xm, y1, ym, xm, ym);
solve(l2, x1, xm, ym + 1, y2, xm, ym + 1);
solve(l2, xm + 1, x2, ym + 1, y2, xm + 1, ym + 1);
cmd.emplace_back(orient[1], xm, ym);
break;
}
case 2:
{
solve(l2, xm + 1, x2, y1, ym, xm + 1, ym);
solve(l2, x1, xm, y1, ym, x, y);
solve(l2, x1, xm, ym + 1, y2, xm, ym + 1);
solve(l2, xm + 1, x2, ym + 1, y2, xm + 1, ym + 1);
cmd.emplace_back(orient[2], xm, ym);
break;
}
case 3:
{
solve(l2, xm + 1, x2, y1, ym, xm + 1, ym);
solve(l2, x1, xm, y1, ym, xm, ym);
solve(l2, x1, xm, ym + 1, y2, x, y);
solve(l2, xm + 1, x2, ym + 1, y2, xm + 1, ym + 1);
cmd.emplace_back(orient[3], xm, ym);
break;
}
case 4:
{
solve(l2, xm + 1, x2, y1, ym, xm + 1, ym);
solve(l2, x1, xm, y1, ym, xm, ym);
solve(l2, x1, xm, ym + 1, y2, xm, ym + 1);
solve(l2, xm + 1, x2, ym + 1, y2, x, y);
cmd.emplace_back(orient[4], xm, ym);
break;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l, x, y;
cin >> l >> x >> y;
solve(l, 0, l - 1, 0, l - 1, x, y);
cout << cmd.size() << '\n';
for (auto &c : cmd)
{
cout << get<0>(c) << ' ' << get<1>(c) << ' ' << get<2>(c) << '\n';
}
}