Given two points (x1, y1) and (x2, y2) in 2-D coordinate system. The task is to count all the paths whose distance is equal to the Manhattan distance between both the given points.
Input: x1 = 2, y1 = 3, x2 = 4, y2 = 5
Input: x1 = 2, y1 = 6, x2 = 4, y2 = 9
Approach: The Manhattan distance between the points (x1, y1) and (x2, y2) will be abs(x1 – x2) + abs(y1 – y2)
Let abs(x1 – x2) = m and abs(y1 – y2) = n
Every path with distance equal to the Manhattan distance will always have m + n edges, m horizontal and n vertical edges. Hence this is a basic case of Combinatorics which is based upon group formation. The idea behind this is the number of ways in which (m + n) different things can be divided into two groups, one containing m items and the other containing n items which is given by m + nCn i.e. (m + n)! / m! * n!.
Below is the implementation of the above approach:
- Pairs with same Manhattan and Euclidean distance
- Distance between two parallel Planes in 3-D
- Distance between a point and a Plane in 3 D
- Puzzle | Minimum distance for Lizard
- Rearrange first N numbers to make them at K distance
- Hammered distance between N points in a 2-D plane
- Program for distance between two points on earth
- Perpendicular distance between a point and a Line in 2 D
- Find points at a given distance on a line of given slope
- Minimum distance to travel to cover all intervals
- Find maximum distance between any city and station
- Minimum distance to the corner of a grid from source
- Check whether it is possible to join two points given on circle such that distance between them is k
- Shortest distance between a Line and a Point in a 3-D plane
- Find maximum and minimum distance between magnets
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.