-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines.cpp
74 lines (67 loc) · 1.86 KB
/
lines.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
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
struct Point {
int x;
int y;
Point() : x(0), y(0) {}
Point(int a, int b) : x(a), y(b) {}
bool operator==(const Point&other)const
{ return x==other.x && y==other.y;}
bool operator<(const Point&other)const
{ return x<other.x ;}
};
class line
{
public:
Point a;
Point b;
bool operator<(const line&other)const
{
return! ( ((a.x-b.x)*(other.a.y-other.b.y)==(a.y-b.y)*(other.a.x-other.b.x)) &&
(
(a.x-b.x)*(other.b.x*other.a.y-other.a.x*other.b.y)==
(other.a.x-other.b.x)*(b.x*a.y-a.x*b.y))
);
}
bool operator==(const line&other)const
{
return ((a.x-b.x)*(other.a.y-other.b.y)==(a.y-b.y)*(other.a.x-other.b.x)) &&
(
(a.x-b.x)*(other.b.x*other.a.y-other.a.x*other.b.y)==
(other.a.x-other.b.x)*(b.x*a.y-a.x*b.y)
);
}
line(Point x,Point y):a(x),b(y){}
};
class Solution {
public:
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.
map<line,set<int> > lines;
for(int i=0;i<points.size();i++)
{
for(int j=i+1;j<points.size();j++)
{
line l(points[i],points[j]);
if(lines.find(l)==lines.end())
lines[l]=set<int>();
lines[l].insert(i);
lines[l].insert(j);
cout<<lines.size()<<endl;
}
}
int most=points.size()>0;
for(map<line,set<int> >::iterator it=lines.begin();it!=lines.end();it++)
most=(int)it->second.size();
return most;
}
};
main()
{
vector<Point> p(2,Point(0,0));
cout<<Solution().maxPoints(p)<<endl;
}