Given a rectangle of height H and width W which has the bottom left corner at (0, 0). The task is to count the number of distinct Rhombi that have all points inside or on the border of the rectangle satisfying the following conditions exists:
- Have non-zero area.
- Have diagonals parallel to the x and y axes.
- Have integer coordinates.
Input: H = 2, W = 2
There is only one rhombus possible with coordinates (0, 1), (1, 0), (2, 1) and (1, 2).
Input: H = 4, W = 4
Approach: Since the diagonals are parallel to the axis, let’s try fixing the diagonals and creating rhombi on them. For the rhombus to have integer coordinates, the length of the diagonals must be even. Let’s fix the length of the diagonals to i and j, the number of rhombi we can form with these diagonal lengths inside the rectangle would be (H – i + 1) * (W – j + 1). Thus, we iterate over all possible values of i and j and update the count.
Below is the implementation of the above approach:
Time Complexity: O(H * W)
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.
- Find the number of rectangles of size 2*1 which can be placed inside a rectangle of size n*m
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Sum of Area of all possible square inside a rectangle
- Count of smaller rectangles that can be placed inside a bigger rectangle
- Check whether a given point lies inside a rectangle or not
- Coordinates of rectangle with given points lie inside
- Check whether a given point lies on or inside the rectangle | Set 3
- Ratio of area of a rectangle with the rectangle inscribed in it
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Check if a point lies on or inside a rectangle | Set-2
- Generate all integral points lying inside a rectangle
- Possible number of Rectangle and Squares with the given set of elements
- Maximum area of rectangle possible with given perimeter
- Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- The biggest possible circle that can be inscribed in a rectangle
- Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
- Rectangle with minimum possible difference between the length and the width
- Count number of squares in a rectangle
- Maximum number of tiles required to cover the floor of given size using 2x1 size tiles
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.