Serious Cow Tag
Time limit1sMemory limit128 MB
Simulate the elimination game where each active cow tags her nearest remaining cow, and report the last cow standing.
- Level
Easy3 of 10
- Topics
- Simulation, Geometry, Implementation, Array
- Solved
- No attempts yet
Problem
Farmer John's cows (), numbered through , are playing a game called Serious Cow Tag. Each cow stands on a distinct grid point in the pasture with integer coordinates satisfying and . The positions are chosen so that the distances between every pair of cows are all different.
The cows take turns in order: cow first, then cow , then cow , and so on. After cow the order wraps back to cow and repeats. A cow that has already been tagged is skipped and never takes a turn again.
On her turn, the active cow looks at every cow still in the game, walks to the closest one, tags her, and returns to her own spot. The tagged cow is immediately out of the game. Because all pairwise distances are distinct, the closest remaining cow is always unique.
The game continues until only one cow is left; that cow is declared the winner.
Farmer John wants to know the winner in advance. Given the cows' positions, determine which cow wins.
Input
- The first line contains a single integer , the number of cows.
- Each of the next lines contains two space-separated integers and , the coordinates of cow (for from to ).
Output
- Print a single line containing the number of the winning cow.
Hint
With three cows, cow goes first and tags her nearest neighbor, cow , who is eliminated and therefore never takes a turn. Cow then tags the only other remaining cow, cow . Cow is the last one standing, so she wins.