-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path149.cpp
More file actions
68 lines (64 loc) · 1.14 KB
/
149.cpp
File metadata and controls
68 lines (64 loc) · 1.14 KB
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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#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) {}
};
class Solution {
public:
int maxPoints(vector<Point>& points) {
if(points.size()<3)
return points.size();
map<float,int> mp;
int ret=0;
for(int i=0;i<points.size();i++)
{
int cnt=0;
for(int j=i+1;j<points.size();j++)
{
if(points[i].x!=points[j].x)
{
if(mp.find(kk(points[i],points[j]))==mp.end()) //ûÓÐ
{
mp[kk(points[i],points[j])]=1;
}
else mp[kk(points[i],points[j])]++;
}
else{
if(points[i].y!=points[j].y) //²»ÖغÏ,´¹Ö±
ret++;
else
{
mp[kk(points[i],points[j])]++;
cnt++;
}
}
}
}
int res=0;
for(auto it=mp.begin();it!=mp.end();it++)
{
if(it->second>res)
res=it->second;
}
if(ret>res)
res=ret;
int num=(1+(int)sqrt((float)(1+8*res)))/2;
return num;
}
private:
float kk(Point a,Point b)
{
return (a.y-b.y)/(a.x-b.x);
}
};