-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxcolinear.cpp
78 lines (61 loc) · 1.6 KB
/
maxcolinear.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
#include <bits/stdc++.h>
using namespace std;
/*
Also solves https://www.codechef.com/problems/CB04
But first line of the input contains the number of test cases T.
*/
struct Point {
int x, y;
Point(int x, int y) : x(x), y(y) {}
Point() {}
Point move_to_upper() const {
if (y > 0) return Point(x, y);
if (y < 0) return Point(-x, -y);
if (x > 0) return Point(x, y);
return Point(-x, y);
}
Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
int operator^(const Point& p) const { return x * p.y - y * p.x; }
bool operator==(const Point& p) const { return x == p.x && y == p.y; }
};
bool cmp(const Point& p, const Point& q) {
return (p.move_to_upper() ^ q.move_to_upper()) > 0;
}
int N;
int count(vector<Point>& points) {
if (points.empty()) return 1;
int ans = 2;
int curr = 2;
for (int i = 1; i < (int)points.size(); i++) {
Point p = points[i];
Point prev_point = points[i - 1];
if ((p ^ prev_point) == 0)
curr++;
else
curr = 2;
ans = max(ans, curr);
}
return ans;
}
void solve() {
vector<Point> points;
for (int i = 0; i < N; i++) {
Point p;
scanf("%d %d", &p.x, &p.y);
points.push_back(p);
}
int ans = 1;
for (const Point& center : points) {
vector<Point> centered_points;
for (const Point& p : points) {
if (p == center) continue;
centered_points.push_back(p - center);
}
sort(centered_points.begin(), centered_points.end(), cmp);
ans = max(ans, count(centered_points));
}
printf("%d\n", ans);
}
int main() {
while (scanf("%d", &N) == 1 && N > 0) solve();
}