[英]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))
边界。
A
from the point M
to the center of the circle - O(1)
. 计算从点M
到圆心的角度A
- O(1)
。 I
on the circumference with largest angle less than A
- O(log(n))
. 使用二分搜索在圆周上找到最大角度小于A
- O(log(n))
的点I
M
is either I
or I+1
. 由于圆是凸的,因此最接近M
点是I
或I+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的点。
Note that simple binary search of a point closest to M will not work here, eg, 注意,最接近M的点的简单二进制搜索在这里不起作用,例如,
To perform the search operation using planar cuts, 要使用平面切割执行搜索操作,
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.