Find the nearest dot in a 2D space

前端 未结 4 1333
庸人自扰
庸人自扰 2021-02-19 21:17

Yesterday I read a problem which can be translated into the following problem with slight modification:

The coordinate of a dot is expressed by (x, y) in a 2D space.

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-19 21:46

    Practically we can sort the points in x-coordinate, then start from the point whose x difference is most closed to the target, and we scan to both left and right, and stop scanning to one direction as soon as the next point's x difference in that direct is already bigger than smallest distance found so far. Divide Conquer is still linear if you divide to two half but do not discard either half.

提交回复
热议问题