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
| #include <bits/stdc++.h> using namespace std;
#define lu ans(x + l - 1, y + l - 1, x, y, l) #define ru ans(x + l - 1, y + l, x, y + l, l) #define ld ans(x + l, y + l - 1, x + l, y, l) #define rd ans(x + l, y + l, x + l, y + l, l)
void ans(long long tarx, long long tary, long long x, long long y, long long len) { if (len == 1) return; int l = len / 2; if (tarx < l + x && tary < l + y) { cout << x + l << " " << y + l << " " << "1" << endl; ans(tarx, tary, x, y, l); ru; ld; rd; } if (tarx < l + x && tary >= l + y) { cout << x + l << " " << y + l - 1 << " " << "2" << endl; ans(tarx, tary, x, y + l, l); lu; ld; rd; } if (tarx >= x + l && tary < l + y) { cout << x + l - 1 << " " << y + l << " " << "3" << endl; ans(tarx, tary, x + l, y, l); lu; ru; rd; } if (tarx >= x + l && tary >= l + y) { cout << x + l - 1 << " " << y + l - 1 << " " << "4" << endl; ans(tarx, tary, x + l, y + l, l); lu; ru; ld; } } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); long long k, tarx, tary; cin >> k >> tarx >> tary; ans(tarx, tary, 1, 1, pow(2, k)); return 0; }
|