GPS on a Flat Earth
Time limit1sMemory limit1024 MB
Given towers with Manhattan distances to a user at integer coordinates, list every integer point that matches all distances exactly.
- Level
Medium6 of 10
- Topics
- Math, Implementation, Intervals
- Solved
- No attempts yet
Problem
On the day aliens finally attacked humanity, nobody could have predicted their choice of weapon. No nuclear weapons, meteors, lasers, or giant monsters. Instead, they subjugated the planet with the power of physics.
The aliens flattened Earth into a two-dimensional surface, which permanently ended our space travel. Humanity survived and resumed daily life as best it could. This two-dimensional world requires changes to many things, including GPS (Global Positioning System).
GPS normally uses radio waves to measure the Euclidean distances from the user to several reference points (satellites), then computes the user's coordinates from those distances. The flat Earth creates two differences that we must adapt to:
- With no satellites in orbit, radio towers must be used instead. Because the surface is flat, each radio tower covers the entire planet.
- Radio waves propagate differently in two dimensions, so the calculation must switch from Euclidean to Manhattan distance. For any two points and , the Manhattan distance is .
Your task is to write software for these adapted GPS calculations. Given reference radio towers and the Manhattan distance from each tower to the user, output all possible user locations. A possible location must be at exactly the measured Manhattan distance from every reference tower. Because the GPS is still in its initial test phase, the user's true location has integer coordinates.
Input
The first line contains an integer (), the number of reference radio towers.
Each of the next lines contains three integers , , and (, ). This means the tower at is at Manhattan distance from the GPS user. No two towers share the same location. The input data is reliable, and the set of possible user locations with integer coordinates is guaranteed to be non-empty and finite.
Output
Output several lines. Each line contains a different pair of integers and , meaning that is a user location compatible with the input data. Sort the lines by non-decreasing , breaking ties by increasing .