Given a number N, the task is to find the integer points (x, y) such that 0 <= x, y <= N and Manhattan distance between any two points will be atleast N.
Input: N = 3 Output: (0, 0) (0, 3) (3, 0) (3, 3) Input: N = 4 Output: (0, 0) (0, 4) (4, 0) (4, 4) (2, 2)
- Manhattan Distance between two points (x1, y1) and (x2, y2) is:
|x1 – x2| + |y1 – y2|
- Here for all pair of points this distance will be atleast N.
- As 0 <= x <= N and 0 <= y <= N so we can imagine a square of side length N whose bottom left corner is (0, 0) and top right corner is (N, N).
- So if we place 4 points in this corner then Manhattan distance will be atleast N.
- Now as we have to maximize the number of the point we have to check is there any available point inside the square.
- If N is even then middle point of the square which is (N/2, N/2) is integer point, otherwise, it will be float value as N/2 is not a integer when N is odd.
- So the only available position is the middle point and we can put a point there only if N is even.
- So number of points will be 4 if N is odd and if N is even then the number of points will be 5.
Below is the implementation of the above approach:
(0, 0) (0, 8) (8, 0) (8, 8) (4, 4)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count paths with distance equal to Manhattan distance
- Sum of Manhattan distances between all pairs of points
- Pairs with same Manhattan and Euclidean distance
- Minimum Manhattan distance covered by visiting every coordinates from a source to a final vertex
- Maximum Manhattan distance between a distinct pair from N coordinates
- Ways to choose three points with distance between the most distant points <= L
- Find the number of points that have atleast 1 point above, below, left or right of it
- Find a point such that sum of the Manhattan distances is minimized
- Find the original coordinates whose Manhattan distances are given
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Haversine formula to find distance between two points on a sphere
- Find the maximum possible distance from origin using given points
- Find integral points with minimum distance from given set of integers using BFS
- Find points at a given distance on a line of given slope
- Number of Integral Points between Two Points
- Prime points (Points that split a number into two primes)
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Minimum number of points to be removed to get remaining points on one side of axis
- Steps required to visit M points in order on a circular ring of N points
- Find the minimum sum of distance to A and B from any integer point in a ring of size N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.