-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints.cpp
59 lines (52 loc) · 1.64 KB
/
points.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<iostream>
#include<set>
#include<utility>
#include<vector>
#include<map>
using namespace std;
struct Point {
int x;
int y;
Point() : x(0), y(0) {}
Point(int a, int b) : x(a), y(b) {}
};
int maxPoints(vector<Point> &points) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
//15:43
map<pair<float,float>,set<int> >m;
map<int,set<int> > n;
for(int i=0;i<points.size();i++)
{
for(int j=i+1;j<points.size();j++)
{
float k,t;
if(points[i].x!=points[j].y)
{
k=(points[i].y-points[j].y)/((float)(points[i].x-points[j].x));
t=points[i].y-k*points[i].x;
pair<float,float> p=make_pair(k,t);
if(m.find(p)==m.end())
m[p]=set<int>();
m[p].insert(i);
m[p].insert(j);
}
else
{
if(n.find(points[i].x)==n.end())
n[points[i].x]=set<int>();
n[points[i].x].insert(i);
n[points[i].x].insert(j);
}
}
}
int maxn=0;
for(map<pair<float,float>,set<int> >::iterator it=m.begin();it!=m.end();it++)
maxn=max(maxn,(int)it->second.size());
for(map<int,set<int> >::iterator it=n.begin();it!=n.end();it++)
maxn=max(maxn,(int)it->second.size());
return maxn;
}
main()
{
}