-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path101Hack53_P2.cpp
More file actions
53 lines (39 loc) · 1.13 KB
/
Copy path101Hack53_P2.cpp
File metadata and controls
53 lines (39 loc) · 1.13 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
// code_report Solution
// https://youtu.be/6rEp_F7CTH0
#include <vector>
#include <iostream>
using namespace std;
void fillBoard (int n, int m, int x, int y) {
bool solvable = (n*m - x - y) % 2 == 0; // if tiles to fill not even, can't solve
if (solvable) {
vector<int> v;
vector<vector<int>> res;
int s = 1; // state
int c = 0; // count
vector<vector<int>> li = { { 0, m, 1 },{ m - 1, -1, -1 } }; // loop info for state 0, 1
for (int i = 0; i < n; i++) {
if (v.size () == 0 && i != 0) s = ((n - i) % 2 == 0); // set state for special case
else s = 1 - s; // switch state
for (int j = li[s][0]; j != li[s][1]; j += li[s][2]) {
if (c >= x && c < n*m - y) {
if (j >= m - y && i == n - 1) solvable = false; // run into Y-deleted squares
v.push_back (i + 1);
v.push_back (j + 1);
if (v.size () == 4) {
res.push_back (v);
v.clear ();
}
}
c++;
}
}
if (solvable) {
cout << "YES" << endl << ((n*m - x - y) / 2) << endl;
for (const auto& v : res) {
for (const auto& e : v) cout << e << ' ';
cout << endl;
}
}
}
if (!solvable) cout << "NO" << endl;
}