-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcode149.cpp
35 lines (35 loc) · 1.11 KB
/
lcode149.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
class Solution {
public:
int maxPoints(vector<vector<int>>& points) {
int n=points.size();
int res=0;
if(n<=2)return n;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int temp=2;
vector<int> p1=points[i],p2=points[j];
vector<bool> fg(n,0);
fg[i]=1;
fg[j]=1;
if(p1[0]==p2[0]){
for(int k=0;k<n;k++){
if(fg[k]==0&&points[k][0]==p1[0])
temp++;
}
if(temp>res)
res=temp;
}
else{
double slop=double(p1[1]-p2[1])/(p1[0]-p2[0]);
for(int k=0;k<n;k++){
if(fg[k]==0&&abs(points[k][1]-slop*(points[k][0]-p1[0])-p1[1])<1e-8&&abs(points[k][1]-slop*(points[k][0]-p2[0])-p2[1])<1e-8)
temp++;
}
if(temp>res)
res=temp;
}
}
}
return res;
}
};