One Iteration of 1D K-Means
Wexford Couriers also runs a rural route that is one long road, so every drop-off is a single number: how far along the road it sits. Two depots are under consideration, each given by its own position on that road, and the positions are written in the order the planners happen to prefer rather than in order along the road. One round is wanted, and only one: every drop goes to the depot it is nearer to, then each depot moves to the balance point of the drops it took. A drop exactly the same distance from both goes to the first depot.
Task: Print where each depot sits after one round.
Input
The first line holds the two starting depot positions, separated by a single space. The second line holds one integer n, the number of drops. The third line holds the n drop positions, separated by single spaces.
Output
Two lines. First the moved position of the depot given first, then the moved position of the depot given second, each rounded to 2 decimal places and each on its own line.
Example:
Input:
0 10
5
1 2 3 8 9
Output:
2.00
8.50
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in