-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknightInWarGrid_UVA11906.cpp
125 lines (100 loc) · 2.62 KB
/
knightInWarGrid_UVA11906.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>
using namespace std;
ifstream fin("knightInWarGrid_UVA11906.in");
ofstream fout("knightInWarGrid_UVA11906.out");
struct point
{
int y;
int x;
};
bool g(int y, int x, int c, int r)
{
return y >= 0 && y <= c - 1 && x >= 0 && x <= r - 1;
}
void mark(int y, int x, int n, int m, vector<vector<char>> & a)
{
int c = a.size(), r = a[0].size();
vector<int> pY = {n, n, m, m, -1 * n, -1 * n, -1 * m, -1 * m},
pX = {m, -1 * m, n, -1 * n, m, -1 * m, n, -1 * n};
int _count = 0;
for (int p = 0; p <= 7; ++p)
{
int nowY = y + pY[p], nowX = x + pX[p];
if (g(nowY, nowX, c, r) == true)
{
if (a[nowY][nowX] != 'w')
{
++_count;
}
}
}
if (m == n || n == 0 || m == 0)
{
_count /= 2;
}
if(_count % 2 == 0)
{
a[y][x] = 'e';
}
else
{
a[y][x] = 'o';
}
}
int main()
{
int testCase; fin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
int c, r, n, m; fin >> r >> c >> m >> n;
vector<vector<char>> a(c, vector<char>(r, '.'));
int w; fin >> w;
for (int c = 1; c <= w; ++c)
{
int y, x; fin >> x >> y;
a[y][x] = 'w';
}
vector<int> pY = {n, n, m, m, -1 * n, -1 * n, -1 * m, -1 * m},
pX = {m, -1 * m, n, -1 * n, m, -1 * m, n, -1 * n};
queue<point> q;
point _temp{0, 0};
q.push(_temp);
while (!q.empty())
{
point now = q.front();
q.pop();
int y = now.y, x = now.x;
if (a[y][x] != '.')
{
continue;
}
mark(y, x, n, m, a);
for (int p = 0; p <= 7; ++p)
{
int nowY = y + pY[p], nowX = x + pX[p];
if (g(nowY, nowX, c, r) == true)
{
point temp{nowY, nowX};
q.push(temp);
}
}
}
int ansE = 0, ansO = 0;
for (int y = 0; y <= c - 1; ++y)
{
for (int x = 0; x <= r - 1; ++x)
{
if (a[y][x] == 'e')
{
++ansE;
}
else if (a[y][x] == 'o')
{
++ansO;
}
}
}
fout << "Case " << t << ": " << ansE << ' ' << ansO << '\n';
}
return 0;
}