Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int visiblePoints(int[][] points) {
- int maxMatches = 0;
- double diff;
- int matches = 0;
- int length = points.Length;
- if (length == 1)
- return 1;
- double[] phi = new double[length];
- for(int i = 0; i < length; i++)
- {
- phi[i] = Math.Atan((double) points[i][1]/points[i][0]);
- if (points[i][0]<=0)
- {
- phi[i] += Math.PI;
- }
- }
- Array.Sort(phi);
- int j;
- for(int i = 0; i < length; i++)
- {
- j = 0;
- while (inView(phi[i],phi[(i+j)%length]))
- {
- j++;
- }
- if (matches < j)
- matches = j;
- }
- return matches;
- }
- bool inView(double point, double target)
- {
- double diff = target-point;
- return (diff < Math.PI/4 + 0.00000000000001 && diff >= 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement