Forest for the Trees
InterviewTime limit2sMemory limit1024 MB
Given a map of tree coordinates and sensor readings taken at an unknown heading, find the robot's grid position, or report Impossible or Ambiguous.
- Level
Medium5 of 10
- Topics
- Hash map, Brute force, Implementation
- Solved
- No attempts yet
Problem
You have sent a robot into a forest, and it has gotten lost. The robot has a sensor that detects all trees around it, regardless of occlusions. Unfortunately, all trees in this forest look alike. You have a map of all the trees as points. Every tree is at an integer coordinate, but not every integer coordinate is occupied, since this used to be a tree farm.
The robot always places itself at integer coordinates and aligned with the positive or negative or axis. It is never at the same location as a tree. Its heading relative to the map is unknown. Each sensor reading is a tuple (distance to the right of the robot, distance forward of the robot). Either value can be negative, because the sensor covers all directions. Find where the robot is.
Input
The first line contains three integers , , and : the number of trees in the forest, the number of trees sensed by the robot, and the maximum Manhattan distance (sum of the absolute and distances) of any sensor reading. Each of the next lines contains two integers and , the location of a tree in the global coordinate system. Each of the final lines contains two integers. The first integer is the distance along the axis perpendicular to the robot's heading, and the second integer is the distance along the axis parallel to the robot's heading.
It is guaranteed that for all . Also, , , , and for every tree.
Output
Print the and location of the robot as two integers separated by a space. If no location on the map could produce the given sensor values, print "Impossible". If two or more distinct locations and/or orientations could produce the given sensor values, print "Ambiguous".