Find the most points enclosed in a fixed size circle

后端 未结 4 1772
傲寒
傲寒 2020-12-30 08:06

This came up when a friend talked about a programming competition, and we wondered what the best approach was:

Given a list of points, find the centre of a circle of

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 08:51

    Unless I've missed something obvious I think there is a simple answer.

    For a rectangular area MxN, number of points P, radius R:

    • Initialise a map (e.g. 2D array of int) of your MxN area to all zeroes
    • For each of your P points
      • increment all map points within radius R by 1
    • Find map element with maximum value - this will be the centre of the circle you are looking for

    This is O(P), assuming P is the variable of interest.

提交回复
热议问题