Fast algorithm to find the x closest points to a given point on a plane

后端 未结 4 583
猫巷女王i
猫巷女王i 2020-12-05 11:59

I would like to find a fast algorithm in order to find the x closest points to a given point on a plane.

We are actually dealing with not too many points (between 1

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 12:31

    To make this more efficent. lets say the distance is k. Take all points with x coordinates between x-k and x+k. similarly take, y-k and y+k. So you have removed all excess coordinates. now make distance by (x-x1)^2 + (y-y1)^2. Make a min heap of k elements on them , and add them to the heap if new point < min(heap). You now have the k minimum elements in the heap.

提交回复
热议问题