-
Notifications
You must be signed in to change notification settings - Fork 1
/
UVA_11906.cpp
64 lines (57 loc) · 1.36 KB
/
UVA_11906.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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define endl "\n"
#define newline cout << "\n"
#define puts(_content_) cout << _content_ << "\n"
using namespace std;
typedef pair<int, int> ii;
int R,C,M,N,K;
int answer[2];
int mp[101][101];
bool visited[101][101];
set<ii> add;
inline bool canMove(int x, int y) {
return (x >= 0 && x < R && y >= 0 && y < C && mp[x][y] != -1);
}
void dfs(int x, int y) {
visited[x][y] = true;
int cnt = 0;
for(auto it : add) {
int nx = x + it.first;
int ny = y + it.second;
if(canMove(nx, ny)) {
++cnt;
if(!visited[nx][ny]) dfs(nx, ny);
}
}
++answer[cnt & 1];
}
int main() {
#ifndef Home
freopen ("input.txt", "r", stdin);
#endif
int testCases;
cin >> testCases;
FOR(cas, 1, testCases) {
answer[0] = answer[1] = 0;
memset(mp, 0x00, sizeof mp);
memset(visited, false, sizeof visited);
add.clear();
cin >> R >> C >> M >> N >> K;
int r, c;
REP(i, 0, K) {
cin >> r >> c;
mp[r][c] = -1;
}
int x[] = {-M, -M, -N, -N, N, N, M, M};
int y[] = {-N, N, -M, M, -M, M, -N, N};
REP(i, 0, 8) {
add.insert(ii(x[i], y[i]));
}
dfs(0, 0);
cout << "Case " << cas << ": " << answer[0] << " " << answer[1] << endl;
}
return 0;
}