Given two positive integers n and m. The task is to count number of parallelogram that can be formed of any size when n horizontal parallel lines intersect with m vertical parallel lines.
Input : n = 3, m = 2 Output : 3 2 parallelograms of size 1x1 and 1 parallelogram of size 2x1. Input : n = 5, m = 5 Output : 100
The idea is to use Combination, which state, number of ways to choose k items from given n items is given by nCr.
To form a parallelogram, we need two horizontal parallel lines and two vertical parallel lines. So, number of ways to choose two horizontal parallel lines are nC2 and number of ways to choose two vertical parallel lines are mC2. So, total number of possible parallelogram will be nC2 x mC2.
Below is C++ implementation of this approach:
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.
- Total number of triangles formed when there are H horizontal and V vertical lines
- Number of horizontal or vertical line segments to connect 3 points
- Count of parallelograms in a plane
- Maximum number of region in which N non-parallel lines can divide a plane
- Number of lines from given N points not parallel to X or Y axis
- Find whether only two parallel lines contain all coordinates points or not
- Distance between two parallel lines
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Count squares possible from M and N straight lines parallel to X and Y axis respectively
- Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points
- Count of intersections of M line segments with N vertical lines in XY plane
- How to check if two given line segments intersect?
- Given n line segments, find if any two segments intersect
- Check if two given circles touch or intersect each other
- Slope of the line parallel to the line with the given slope
- Program to check if the points are parallel to X axis or Y axis
- Distance between two parallel Planes in 3-D
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Count of Squares that are parallel to the coordinate axis from the given set of N points
- Missing vertex among N axis-parallel rectangles
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.
Improved By : 29AjayKumar