Claustrophobic Cows
InterviewTime limit1sMemory limit128 MB
Given up to 2000 points, find the unique pair with the smallest Euclidean distance and print their ids in increasing order.
- Level
Medium6 of 10
- Topics
- Geometry, Divide and conquer, Sorting, Brute force
- Solved
- No attempts yet
Problem
Farmer John's cows are numbered through , and they really hate being too close to one another.
Each cow is located at integer coordinates . The distance between two cows is the Euclidean distance .
Among all pairs of cows, exactly one pair is closest together. Find these two closest cows and print their id numbers in increasing order.
Constraints
Input
- Line 1: A single integer .
- Lines 2 to : Line contains the coordinates of cow as two space-separated integers and .
Output
- Line 1: The ids of the two closest cows, in increasing order, separated by a single space.