1515. Best Position for a Service Centre
Last updated
Last updated
**Input:** positions = [[0,1],[1,0],[1,2],[2,1]]
**Output:** 4.00000
**Explanation:** As shown, you can see that choosing [xcentre, ycentre] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.**Input:** positions = [[1,1],[3,3]]
**Output:** 2.82843
**Explanation:** The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2.82843**Input:** positions = [[1,1]]
**Output:** 0.00000**Input:** positions = [[1,1],[0,0],[2,0]]
**Output:** 2.73205
**Explanation:** At the first glance, you may think that locating the centre at [1, 0] will achieve the minimum sum, but locating it at [1, 0] will make the sum of distances = 3.
Try to locate the centre at [1.0, 0.5773502711] you will see that the sum of distances is 2.73205.
Be careful with the precision!**Input:** positions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]
**Output:** 32.94036
**Explanation:** You can use [4.3460852395, 4.9813795505] as the position of the centre.