-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathB_InterceptLessLines_intended.cpp
More file actions
72 lines (56 loc) · 1.31 KB
/
B_InterceptLessLines_intended.cpp
File metadata and controls
72 lines (56 loc) · 1.31 KB
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
#include "bits/stdc++.h"
using i64 = long long;
void solve()
{
int n;
std::cin >> n;
std::vector<std::pair<i64, i64>> a;
for (int i = 0; i < n; i++) {
i64 x, y;
std::cin >> x >> y;
if (x != 0 or y != 0) {
a.emplace_back(x, y);
}
}
if (n == 1 and !a.empty()) {
std::cout << "1\n";
return;
}
std::set<std::pair<i64, i64>> slopes;
auto convertToFraction = [&](i64 x, i64 y) -> std::pair<int, int>
{
if (std::abs(x) == 0) {
y = 1;
x = 0;
} else if (std::abs(y) == 0) {
x = 1;
y = 0;
} else {
i64 g = std::gcd(x, y);
assert(g != 0);
x /= g, y /= g;
}
if ((x ^ y) < 0) {
x = -std::abs(x), y = std::abs(y);
} else {
x = std::abs(x), y = std::abs(y);
}
return {x, y};
};
for (auto [x, y] : a) {
slopes.insert(convertToFraction(x, y));
}
std::cout << slopes.size() << "\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::freopen("handmade_7.txt", "r", stdin);
std::freopen("handmade_7_out.txt", "w", stdout);
int t = 1;
std::cin >> t;
while (t--)
solve();
return 0;
}