Factory
InterviewTime limit10sMemory limit512 MB
Find any point in the plane that minimizes the sum of Euclidean distances to n given store locations, within a relative error of 1e-6.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Binary search, Divide and conquer
- Solved
- No attempts yet
Problem
"ASD Inc." is a worldwide quadcopter manufacturer. They recently decided to build a new factory, which will make a brand new line of quadcopters. However, the company has not yet decided where to build it.
The factory should be placed in a location that makes the cost of delivering produced quadcopters to stores minimal. There are stores that are interested in selling the new model. The produced quadcopters will deliver themselves to the stores, each one flying straight from the factory to its selected store. If the Euclidean distance between the factory and some store equals , then the monthly cost of delivery is exactly bitcoins.
The factory can be built anywhere, even if there is some store at this point (in that case, delivery is costless). Given the coordinates of the stores, find the optimal place to build the factory.
Input
The first line of input contains the number of test cases (). The descriptions of the test cases follow.
The first line of each test case contains the number of stores ().
Each of the next lines contains two integers () denoting coordinates of the stores.
You may assume that no two stores occupy the same spot.
Output
For each test case, output two numbers denoting the coordinates of a point which minimizes sum of distances to the stores. If there are multiple such points, output any one of them.
If the cost of the optimal solution is , then solution with cost will be considered correct if .