Question 1 An energy company needs a control center to manage a distributed wind farm.…
- User
Question 1 An energy company needs a control center to manage a distributed wind farm. Due to terrain and other considerations, the cost to reach a group of windmills is specific to each location. Locate the control center to minimize the cost. Return the minimum cost.
The control center is located at integral coordinates (cx, cy). Wind farm i is located at integral coordinates (x[i], y[i]). The distance farm i is the Manhattan distance, i.e., distance[i] = |x[i] - cx| + |y[i] - cy|. The cost to connect farm i is premium[i] * distance[i]. The total cost to connect all farms to the control center is the sum of the cost to connect each farm. Determine the minimum cost to connect to the control center.
Example css Copy code x = [1, 3, 2, 4] y = [1, 2, 3, 4] premium = [1, 3, 2, 4] Farm # Location Distance Premium Cost 0 (1,1) 1-3 + 1 (3,2) 3-3 + 2 (2,3) 2-3 + 3 (4,4) 4-3 + The cost to connect all wind farms is 17.
Function Description Complete the function windFarms in the editor below.
windFarms has the following parameter(s):
int premium[n]: the distance multiplier for the cost to connect int x[n]: x coordinates of the wind farms int y[n]: y coordinates of the wind farms Returns:
int: the minimum cost to connect the wind farms Constraints 1 ≤ n ≤ 10^3 1 ≤ x[i], y[i] ≤ 10^4 1 ≤ premium[i] ≤ 50
give answer in python
- Assistant