-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConnected_Component_on_a_Chessboard.cpp
More file actions
67 lines (51 loc) · 1.48 KB
/
Connected_Component_on_a_Chessboard.cpp
File metadata and controls
67 lines (51 loc) · 1.48 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
#define DEBUG
#define MAXN 1000000
#include <bits/stdc++.h>
using namespace std;
int main ()
{
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
int query, black, white;
int delta = 0; // if white 0, black 1
cin >> query;
// consider 4 Black, 5 White
/*
make the main centre line : WBWBWBWB or BWBWBWBW
then make the remain block next to the centre line
if remain put to the begin and the end of the centre line
*/
while (query--) {
cin >> black >> white;
int less = min(black, white), flag = (less==black)?1:0;
int more = (flag==1)?white:black;
if (more > 3*less+1) {
printf("NO\n");
continue;
}
printf("YES\n");
// centre line
for (int i = 1; i <= less; ++i, --more) {
printf("2 %d\n", 2*i+flag);
printf("2 %d\n", 2*i+flag+1);
}
// nearby block
bool leak ;
if (more > 0) leak = false;
else leak = true ;
for (int i = 1; i <= less && !leak; ++i) {
for (int j = 1; j <= 3 && !leak; j+=2) {
more--;
if (more == 0) leak = true;
printf("%d %d\n", j, 2*i+flag);
}
}
// remain
for (int i = 1; i < 3 && more > 0; ++i, more--) {
printf("2 %d\n", (i==1)?1+flag:2*less-1+flag);
}
}
return 0;
}