Assigning a Point to Its Cluster
Wexford Couriers is putting pickup lockers around a city. A shortlist of candidate sites is already marked on the map, and every customer address has to be booked to exactly one of them: the site that address would travel least far to reach, measured as the crow flies rather than along the streets. Before the whole address file goes through, the planners want one address checked by hand.
Task: Print which candidate site this address is booked to.
Input
The first line holds one integer k, the number of candidate sites. Each of the next k lines holds one site's two map coordinates, separated by a single space. The last line holds the address's two coordinates in the same form.
Output
One line holding the booked site's position in the list, counting the first site as 0. If the address sits exactly the same distance from two sites, book it to whichever of them appears earlier in the list.
Example:
Input:
2
0 0
10 10
1 1
Output:
0
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