Manhattan Positioning System
Time limit2sMemory limit512 MB
Given beacons with known grid positions and Manhattan distances to an unknown receiver, decide whether the receiver position is unique, ambiguous, or impossible.
- Level
Medium6 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
The Manhattan Positioning System (MPS) is a variant of GPS built for large cities. MPS treats every position as a lattice point on a regular two dimensional grid, and writes a position as a pair of integers .
To find its own position, an MPS receiver first measures the distance to a number of beacons. Every beacon has a known, fixed position. MPS signals travel along the streets of the city, that is along the and axes only, and never diagonally across a block. A receiver at that measures the distance to a beacon at therefore reads the Manhattan distance .
You are given the positions of several beacons and the measured distance from the receiver to each of them. Determine the position of the receiver. The receiver sits on an integer grid point, because MPS does not support fractional coordinates.
Input
The first line contains an integer , the number of beacons (). Each of the next lines contains three integers , , with and . The pair is the position of beacon , and is the Manhattan distance between the receiver and beacon .
No two beacons have the same position.
Output
If exactly one receiver position agrees with the input, print one line with two integers and , the position of the receiver.
If more than one receiver position agrees with the input, print one line with the word uncertain.
If no receiver position agrees with the input, print one line with the word impossible.