简体   繁体   English

给定一个具有N个定义点的圆和圆外的点M,找到N.O(LogN)集合中最接近M的点

[英]Given a circle with N defined points and a point M outside the circle, find the point that is closest to M among the set of N. O(LogN)

http://www.glassdoor.com/Interview/Google-Interview-RVW2382108.htm http://www.glassdoor.com/Interview/Google-Interview-RVW2382108.htm

I have tried to come with a solution to this problem. 我试图找到解决这个问题的方法。 But I have not been successful.. Can any one please give me a hint as to how to proceed with this problem. 但我还没有成功..任何人都可以给我一个关于如何处理这个问题的提示。

I will take 2 pair of two points each. 我将分别拿2对两分。 That is, I will make 2 chords. 也就是说,我将制作2个和弦。 Find out their perpendicular bisector. 找出他们的垂直平分线。 Using those bisectors, I will find out the center of the circle... 使用这些平分线,我会发现圆圈的中心......

Moreover, I will come up with the equation of the circle. 而且,我会想出圆圈的等式。 And find the point of intersection of the point M with the circle... That should be closest point. 并找到点M与圆的交点......那应该是最近点。 However, that point may or may not exist in the set of N points 但是,该点可能存在也可能不存在于N点的集合中

Thanks. 谢谢。

Assuming that the points on the circumference of the circle are "in-order" (ie sorted by angle about the circle's center) you could use an angle-based binary search, which should achieve the O(log(n)) bounds. 假设圆周上的点是“有序的”(即按圆圈中心的角度排序),您可以使用基于角度的二分搜索,它应该达到O(log(n))边界。

  1. Calculate the angle A from the point M to the center of the circle - O(1) . 计算从点M到圆心的角度A - O(1)
  2. Use binary search to find the point I on the circumference with largest angle less than A - O(log(n)) . 使用二分搜索在圆周上找到最大角度小于A - O(log(n))的点I
  3. Since circles are convex the closest point to M is either I or I+1 . 由于圆是凸的,因此最接近M点是II+1 Calculate distance to both and take the minimum - O(1) . 计算两者的距离并取最小值 - O(1)

To find a point closest to M, we need to do binary elimination of points based on planar cuts. 为了找到最接近M的点,我们需要基于平面切割对点进行二元消除。 A little pre-processing of the input points is needed after which we can find a point closest to any given point M in O(lgn) time. 需要对输入点进行一点预处理,之后我们可以在O(lgn)时间内找到最接近任何给定点M的点。

  1. Calculate (if not given) polar representation of points in (r,θ) format where r is the distance from center and θ is the angle from x-axis in the range (-180,180]. 计算(如果没有给出)(r,θ)格式的点的极坐标表示,其中r是距中心的距离,θ是x轴在范围内的角度(-180,180)。
  2. Sort all N points in increasing order of their angle from x-axis. 按x轴的角度递增顺序对所有N个点进行排序。

Note that simple binary search of a point closest to M will not work here, eg, 注意,最接近M的点的简单二进制搜索在这里不起作用,例如,

  • if the given points are sorted such that θ = (-130,-100,-90,-23,-15,0,2,14,170), then for a point M with θ = -170, binary search will give -130 (40 degrees away) as the closest point whereas 170 (20 degrees away) is the closest point to M. 如果给定的点被排序使得θ=(-130,-100,-90,-23,-15,0,2,14,170),则对于具有θ= -170的点M,二分搜索将给出-130 (40度远)作为最近点,而170(20度距离)是距离M最近的点。
  • if we ignore the sign while sorting (thinking that it will produce correct output), our new sorted array will look like θ = (0,2,14,15,23,90,100,130,170), binary search for a point M with θ = -6 will yield the result should be either 2 or 14 whereas 0 is the closest point to M in this case. 如果我们在排序时忽略符号(认为它会产生正确的输出),我们的新排序数组将看起来像θ=(0,2,14,15,23,90,100,130,170),二元搜索点M,θ= - 6将产生结果应为2或14,而0是在这种情况下最接近M的点。

To perform the search operation using planar cuts, 要使用平面切割执行搜索操作,

  • Find planar cut line passing through the center of circle and perpendicular to the line connecting the center of the circle with point M. 找到穿过圆心并垂直于连接圆心与点M的直线的平面切割线。
  • Eliminate half of the circular plane [90+θ,-90+θ) or [-90+θ,90+θ) depending upon on in which half of the plane M lies. 根据平面M的哪一半所在,消除圆平面的一半[90 +θ,-90 +θ]或[-90 +θ,90 +θ]。
  • Make planar cuts parallel to the first cut and passing through the point in the middle of the previous plane and eliminate all points in the half of the plane farther from M until there are no points left in the nearer half of the plane, in which case eliminate the nearer half of the plane. 使平面切割平行于第一个切口并穿过前一个平面中间的点,并消除距离M更远的平面的一半中的所有点,直到在平面的较近一半中没有剩余点,在这种情况下消除飞机的近一半。
  • Keep on cutting planes till we are left with one point. 继续切割飞机,直到我们留下一点。 That point is the closest point to M. The total operation takes O(lgn) steps. 这一点是距离M最近的点。总操作需要O(lgn)步。

平面消除

In case the data is skewed and not uniformly spread in the circle, we can optimize our planar cuts such that each cut passes through the median (based on angle) of those points which are left in the search operation. 如果数据偏斜并且不均匀地在圆圈中展开,我们可以优化我们的平面切割,使得每个切割通过搜索操作中留下的那些点的中值(基于角度)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构造一个 O(n) 平均情况算法以从 n 个点的列表中找到最接近的 m 个点 - Construct an O(n) average case algorithm to find closest m points from a list of n points 在 2n+3 个点中找到一个圆的算法,它包含内部 n 个点、外部 n 个点和自身 3 个点 - Algorithm for Finding a circle among 2n+3 points such that it contains n points inside, n points outside and 3 points on itself 在最接近给定点的圆上找到点的最佳方法 - Best way to find a point on a circle closest to a given point 给定 N 个相等的圆(可能重叠)和平面上的 M 个点。 找到包含最大点数的圆 - Given N equal circles (possibly overlapping) and M points on a plane. Find a circle which contains maximum number of points 给定一组n个点(x,y),是否有可能在O(n logn)时间内找到它们之间具有负斜率的点对的数量? - Given a set of n points (x,y), is it possible to find the number of pairs of points with negative slopes between them in O(n logn) time? 给定N点如何找到圆上的最大点数? - Given N points how to find the maximum number of points which are on a circle? 给定2-D平面中的n个点,我们必须在它们之间找到每个点的k个最近邻居 - Given n points in a 2-D plane we have to find k nearest neighbours of each point among themselves 如何使用二元概念从O(log n)时间内的一组点中找到给定查询行的最近点? - How to find a nearest point to a given query line from a set of points in O(log n) time with out using duality concept? 算法在平面中的n个点之间找到一个点以最小化距离之和 - algorithm to find a point among n points in plane to minimize the sum of distances 从一个点找到最近的圆 - Finding closest circle from a point
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM