-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
88 lines (73 loc) · 2.19 KB
/
B.cpp
File metadata and controls
88 lines (73 loc) · 2.19 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1 << 7;
int g[N][N];
int n;
bool valid(int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= n; }
int blocked() { int x; cin >> x; return x; }
void print(int b, int i, int j) {
assert(valid(i, j));
assert(g[i][j] == 0);
g[i][j] = b;
cout << b << ' ' << i << ' ' << j << endl;
// cerr << '\n';
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= n; ++j) {
// cerr << g[i][j] << ' ';
// }
// cerr << '\n';
// }
}
bool blocker(int i, int j) { return valid(i, j) && g[i][j] != 0; }
bool eh(int i, int j, int b) {
return blocker(i, j) && g[i][j] != b;
}
bool soft_spot(int i, int j, int b) {
if (g[i][j]) return 0;
if (blocker(i - 1, j) && g[i - 1][j] == b) return 0;
if (blocker(i + 1, j) && g[i + 1][j] == b) return 0;
if (blocker(i, j - 1) && g[i][j - 1] == b) return 0;
if (blocker(i, j + 1) && g[i][j + 1] == b) return 0;
if (eh(i - 1, j - 1, b))
if (g[i][j - 1] == 0 || g[i - 1][j] == 0) return 0;
if (eh(i - 1, j + 1, b))
if (g[i][j + 1] == 0 || g[i - 1][j] == 0) return 0;
if (eh(i + 1, j - 1, b))
if (g[i][j - 1] == 0 || g[i + 1][j] == 0) return 0;
if (eh(i + 1, j + 1, b))
if (g[i][j + 1] == 0 || g[i + 1][j] == 0) return 0;
return 1;
}
bool place(int to_place) {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (soft_spot(i, j, to_place)) {
print(to_place, i, j);
return 1;
}
return 0;
}
signed main() {
cin >> n;
rep(iterations, 0, n * n) {
int b = blocked();
bool placed = false;
for (int to_place = 1; to_place <= 3 && !placed; ++to_place) {
if (to_place == b) continue;
placed |= place(to_place);
}
assert(placed);
}
}