-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (53 loc) · 936 Bytes
/
Copy pathmain.cpp
File metadata and controls
66 lines (53 loc) · 936 Bytes
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
// 一个平面上的n个点, 找出哪条直线上的点最多.
#include <vector>
#include <map>
#include <algorithm>
#include <list>
struct Point
{
int x;
int y;
Point() : x(0), y(0) {}
Point(int a, int b) : x(a), y(b) {}
};
int MaxPoints(std::vector<Point> &points)
{
if (points.size() < 2)
return points.size();
int size = points.size();
int ret = 0;
for (int i = 0; i < size - 1; ++i)
{
int dup = 0;
int cnt = 1;
int max = 1;
std::map<double, int> mp;
for (int j = i + 1; j < size; ++j)
{
double x = points[i].x - points[j].x;
double y = points[i].y - points[j].y;
if (x == 0 && y == 0)
++dup;
else if (x == 0)
{
++cnt;
max = std::max(cnt, max);
}
else
{
double slope = y / x;
if (mp[slope] == 0)
mp[slope] = 2;
else
++mp[slope];
max = std::max(mp[slope], max);
}
}
ret = std::max(ret, max + dup);
}
return ret;
}
int main()
{
return 0;
}