-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadialSweepNight.cpp
71 lines (54 loc) · 1.65 KB
/
RadialSweepNight.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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct coor {
ll x;
ll y;
};
ll d(coor v1, coor v2) {
return v1.x * v2.x + v1.y * v2.y;
}
ll m(coor v) {
return sqrt(pow(v.x, 2) + pow(v.y, 2));
}
ll c(coor v1, coor v2) {
return v1.y*v2.x - v1.x*v2.y;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio();
int nights;
cin >> nights;
while (nights--) {
vector<ll> seeable;
ll loseable;
coor chair;
cin >> loseable >> chair.x >> chair.y;
double racks;
vector<coor> positions;
cin >> racks;
for (int i = 0; i < racks; i++) {
coor temp;
cin >> temp.x >> temp.y;
positions.push_back(temp);
}
//solving the problem
for (int i = 0; i < racks; i++) {
ll count = 0;
//iterating through the points to check if angles from that point work
coor vector1 = {(positions[i].x - chair.x), (positions[i].y - chair.y)};
for (int j = 0; j < racks; j++) {
coor vector2 = {positions[j].x - chair.x, positions[j].y - chair.y};
if (d(vector1,vector2) >= 0 && c(vector1,vector2) >= 0)
count++;
}
seeable.push_back(count);
}
//checking maximum of servers that are visible
int most_visible = *max_element(seeable.begin(), seeable.end());
if (most_visible >= racks-loseable)
cout << 0 << endl;
else
cout << (racks - loseable) - most_visible << endl;
}
}