-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2083-on_the_side_of_the_road.cpp
59 lines (48 loc) · 1.42 KB
/
2083-on_the_side_of_the_road.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define x first
#define y second
int main() {
int N;
while (cin >> N) {
vector<pii> points(N);
for (auto& p : points) cin >> p.x >> p.y;
vector<tuple<double, ll, pii, pii>> intersections;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
const pii p = points[i];
const pii q = points[j];
if (p.y == q.y) continue;
if (p.x == q.x) {
intersections.emplace_back(p.x, LONG_LONG_MAX, p, q);
continue;
}
const double slope = (p.y - q.y) / (double)(p.x - q.x);
const double b = p.y - slope * p.x;
const ll slope_int = round(slope * 1000000);
intersections.emplace_back(-b / slope, slope_int, p, q);
}
}
vector<int> counts{N};
set<pii> blocked;
set<ll> slopes;
double prev = -numeric_limits<double>::infinity();
sort(intersections.begin(), intersections.end());
for (const auto& [x, slope, p, q] : intersections) {
if (fabs(x - prev) > 1e-8) {
counts.push_back(0);
blocked.clear();
slopes.clear();
prev = x;
}
blocked.emplace(p);
blocked.emplace(q);
slopes.emplace(slope);
counts.back() = N - blocked.size() + slopes.size();
prev = x;
}
cout << set<int>{counts.begin(), counts.end()}.size() << endl;
}
}