P18029 [GeeksforGeeks] Optimum location of point to minimize total distance
提高-
题目描述

Given a set of coordinates points of the form [p, q] and a line L of the form ax + by + c = 0. The task is to find a point on a given line for which the sum of distances from a given set of coordinates is minimum.

Example 1:
Input:
L = {1, -1, -3}
points[] = {{-3, 2}, {-1, 0},
{-1, 2}, {1, 2}, {3, 4}}
Output: 20.77
Explanation: In above figure optimum location of
point of x - y - 3 = 0 line is (2, -1), whose
total distance with other points is 20.77,
which is minimum obtainable total distance.
Example 2:
Input:
L = {2, 1, 4}
points[] = {{-1, 2}, {1, 3},{2, 4}}
Output: 11.20

Your Task:
You don't need to read input or print anything. Your task is to complete the function findOptimumCost() which takes a line L and coordinates and returns an double up to 2 decimal places as output.
Expected Time Complexity: O(NlogN)
Expected Auxiliary Space: O(N)

Constraints:
1 <= N <= 10^{5}
-10^{3 }<= point[i] <= 10^{3}

输入格式

见题面

输出格式

见题面

样例输入
L = {1, -1, -3} points[] = {{-3, 2}, {-1, 0}, {-1, 2}, {1, 2}, {3, 4}}
样例输出
20.77