-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP270.cpp
66 lines (63 loc) · 1.39 KB
/
P270.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
typedef PI Fraq;
#define Nom first
#define Denom second
int gcd(int a, int b) {
int c;
while(a != 0) {
c = a;
a = b%a;
b = c;
}
return b;
}
Fraq reduce(int nom, int denom) {
if(denom < 0) {
denom = -denom;
nom = -nom;
}
int g = gcd(ABS(nom), denom);
return Fraq(nom/g, denom/g);
}
int main() {
string line;
getline(cin, line);
int cases;
stringstream ss1; ss1 << line; ss1 >> cases;
getline(cin, line);
for(int cas = 0; cas < cases; ++cas) {
if(cas != 0)
cout << endl;
// Read points:
vector<Point> pts;
PI pt;
while(true) {
getline(cin, line);
stringstream ss2; ss2 << line;
if(!(ss2 >> pt.XX >> pt.YY))
break;
pts.push_back(pt);
}
sort(pts.begin(), pts.end()); // Sort by x, then y.
int N = (int)pts.size();
// Try where all points are left-most and see how many that lie on various angles:
//cerr << "Handling " << N << " points." << endl;
int best = 0;
for(int a = 0; a < N; ++a) {
PI pa = pts[a];
map<Fraq,int> lines; // line -> count.
int curBest = 0;
for(int b = a+1; b < N; ++b) {
PI pb = pts[b];
Fraq slope = reduce(pa.XX - pb.XX, pa.YY - pb.YY);
++lines[slope];
if(lines[slope] > curBest)
++curBest;
}
++curBest; // Count the point itself.
if(curBest > best)
best = curBest;
}
cout << best << endl;
}
return 0;
}