Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. int visiblePoints(int[][] points) {
  2.     int maxMatches = 0;
  3.     double diff;
  4.     int matches = 0;
  5.     int length = points.Length;
  6.     if (length == 1)
  7.         return 1;
  8.     double[] phi = new double[length];
  9.    
  10.     for(int i = 0; i < length; i++)
  11.     {
  12.         phi[i] =  Math.Atan((double) points[i][1]/points[i][0]);
  13.         if (points[i][0]<=0)
  14.         {
  15.             phi[i] += Math.PI;
  16.         }
  17.     }
  18.    
  19.     Array.Sort(phi);
  20.     int j;
  21.  
  22.     for(int i = 0; i < length; i++)
  23.     {
  24.         j = 0;
  25.         while (inView(phi[i],phi[(i+j)%length]))
  26.         {
  27.             j++;
  28.         }
  29.         if (matches < j)
  30.            
  31.             matches = j;
  32.     }
  33.  
  34.     return matches;
  35. }
  36.  
  37. bool inView(double point, double target)
  38. {
  39.     double diff = target-point;
  40.     return (diff < Math.PI/4 + 0.00000000000001 && diff >= 0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement