Official algorithmic problem description and constraints.
Chef is now a tourist in a foreign land. The land can be modelled as an infinite 2
2-D grid.
Chef is currently at (A,B)
(A,B). There are N
N attractions, the i
i-th attraction at coordinate (Xi,Yi)
(Xi
,Yi
).
Chef wants to visit 1
1 attraction, but he does not care which one. Find the minimum distance Chef needs to travel to reach some attraction.
Here, the distance is measured by the Manhattan Metric, where Chef can only travel along parallel to one of the axes. For example, the distance between (0,0)
(0,0) and (1,1)
(1,1) is 2
2.
For each test case, output on a new line the distance to the closest attraction.
Input
Output
3 1 0 0 1 1 5 50 50 50 49 49 50 50 51 51 50 50 50 2 50 50 100 100 0 1 2 0 99
Test Case 1 : Chef can only visit the attraction at (1,1)
(1,1), which is distance 2
2 as mentioned in the statement.
Test Case 2 : Chef is located at the same point as an attraction. Thus, the minimum distance is 0
0
Detailed video explanations, mathematical intuition, and clean C++ implementation code.