-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCATM_ad_hoc.cpp
70 lines (59 loc) · 1.31 KB
/
CATM_ad_hoc.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
//Solution for The Cats and the Mouse problem on SPOJ: http://www.spoj.com/problems/CATM/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct Cell
{
int row, column;
};
int n, m, k;
Cell mouse, cat1, cat2;
int Distant(Cell start, Cell target) {
return abs(start.row - target.row) + abs(start.column - target.column);
}
bool IsEscapedCell(Cell target) {
if (Distant(mouse, target) < Distant(cat1, target) && Distant(mouse, target) < Distant(cat2, target))
return true;
return false;
}
void Init() {
scanf("%d %d %d", &n, &m, &k);
}
void Work() {
Cell target1, target2;
bool found;
for (int i = 0; i < k; ++i) {
scanf("%d %d %d %d %d %d", &mouse.row, &mouse.column, &cat1.row, &cat1.column, &cat2.row, &cat2.column);
found = false;
for (int row = 1; row <= n; ++row) {
target1 = {row, 1};
target2 = {row, m};
if (IsEscapedCell(target1) || IsEscapedCell(target2)) {
printf("YES\n");
found = true;
break;
}
}
if (!found) {
for (int column = 1; column <= m; ++column) {
target1 = {1, column};
target2 = {n, column};
if (IsEscapedCell(target1) || IsEscapedCell(target2)) {
printf("YES\n");
found = true;
break;
}
}
}
if(!found){
printf("NO\n");
}
}
}
int main() {
Init();
Work();
return 0;
}