在一个平面中的最大共线点 [英] Maximum Collinear points in a plane
问题描述
N
点作为输入。
假设(X1,Y1),(X2,Y2)...(XN,YN)
。
是否有一个非组合溶液找到共线的点的最大数量?他们可以安排在一个奇特的数据结构,这将有助于这种计算?
Is there a non-combinatorial solution to find the maximum number of collinear points? Can they be arranged in a fancy data structure that would help this computation?
推荐答案
对于每一个点i,找坡到其他每个点j和 寻找重复。重复可以通过排序的山坡被发现 比较相邻值。点我是共线的点 每组重复的。保持最大的集轨道,当您去。
For each point i, find the slope to every other point j and look for duplicates. Duplicates can be found by sorting the slopes and comparing adjacent values. Point i is collinear with the points in each set of duplicates. Keep track of the maximal set as you go.
对于每一个我,你有N-1个斜坡,计算和排序和比较。 因此,使用一个(正log n)的排序,所述算法的复杂度是 为O(n ^ 2 log n)的。
For each i, you have n-1 slopes to calculate and sort and compare. Therefore, using a (n log n) sorting, the complexity of the algorithm is O(n^2 log n).
这篇关于在一个平面中的最大共线点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!