1 class Solution {
2 public:
3 const double pi=M_PI;
4 double get_angel(int x1,int y1,int x2,int y2)
5 {
6 return atan(1.0*(y2-y1)/(x2-x1))*180/pi;
7 }
8 int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) {
9 set<double>s;
10 vector<double>a;
11 int ans=0,mx=0;
12 for(auto &p:points)
13 {
14 double tmp;
15 if(p[0]==location[0]&&p[1]==location[1])
16 {
17 ans++;
18 continue;
19 }
20 if(location[0]==p[0])
21 {
22 if(location[1]<p[1])tmp=90.0;
23 else tmp=-90.0;
24 }
25 else
26 {
27 tmp=get_angel(location[0],location[1],p[0],p[1]);
28 if(location[1]<p[1]&&tmp<0)tmp+=180;
29 else if(location[1]>p[1]&&tmp>0)tmp-=180;
30 else if(location[1]==p[1]&&location[0]>p[0])tmp=180;
31 }
32 a.push_back(tmp);
33 a.push_back(tmp+360);
34 }
35 sort(a.begin(),a.end());
36 for(auto &p:a)
37 {
38 int t=upper_bound(a.begin(),a.end(),p+angle)-lower_bound(a.begin(),a.end(),p);
39 mx=max(t,mx);
40 }
41 return ans+mx;
42 }
43 };