-
Notifications
You must be signed in to change notification settings - Fork 1
/
10961 - Chasing after Don Giovanni.cpp
executable file
·98 lines (79 loc) · 2.1 KB
/
10961 - Chasing after Don Giovanni.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
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
int rowL [100000100] ; // coordinates of L
int colL [100000100] ; // at time i
int main()
{
int tc;
cin >> tc;
while ( tc--)
{
int Vir, Vic;
cin >> Vir>> Vic; // V initial location
int Lir , Lic;
cin >> Lir >> Lic; // L initial location
int LS;
cin >> LS;
bool safe = true;
int t = 0;
int mx = 0;
while( LS--)// record L position
{
int r, c;
cin >> r >> c;
mx += max(abs(c - Lic) , abs(r - Lir)); // max time
for ( int j = t ; j< mx; j++)// position at time j
{
rowL[j] = Lir;
colL[j] = Lic;
// Move to destination
if (Lir < r)
Lir++;
else if( Lir > r)
Lir--;
if (Lic < c)
Lic++;
else if( Lic > c)
Lic--;
}
t = mx;
}
int VS;
cin >> VS;
t = 0;
mx = 0;
while ( VS--) // compare V positions with L positions
{
int r, c;
cin >> r >> c;
mx += max(abs(c - Vic) , abs(r - Vir)); // max time
for ( int j = t ; j< mx; j++)// position at time j
{
if (Vir == rowL[j] && Vic == colL[j] )
{
safe = false;
break;
}
// Move to destination
if (Vir < r)
Vir++;
else if( Vir > r)
Vir--;
if (Vic < c)
Vic++;
else if( Vic > c)
Vic--;
}
t = mx;
}
if ( safe )
cout << "Yes" << endl;
else
cout << "No" << endl;
if ( tc )
cout << endl;
}
return 0;
}