Description
Submission
class Solution {
public:
int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) {
vector<double> angles;
int same = 0;
const double pi = 3.1415926;
for(auto p : points) {
double dx = p[0] - location[0];
double dy = p[1] - location[1];
if(dx == 0 && dy == 0) {
same++;
continue;
}
double alpha = atan2(dy, dx);
angles.push_back(alpha);
}
sort(angles.begin(), angles.end());
int n = angles.size();
for(int i = 0; i < n; ++i) {
angles.push_back(angles[i]+2*pi);
}
int ret = 0;
for(int i = 0, j = 0; i < angles.size(); ++i) {
while(j < 2 * n && angles[j] - angles[i] < angle * 1.0 * pi / 180 + 0.00000000001)
j++;
ret = max(ret, j - i);
}
return ret + same;
}
};