Given an equilateral triangle made of dots (.) joined together to form triangle and an integer n which represents the length of the sides of the triangle. The task is to count the number of rectangles that can be inscribed in the given triangle such that:
- Horizontal edges must be parallel to the base of the given triangle.
- Rectangle must only be formed by joining the dots i.e. all the four edges of the rectangle must touch the dots on the triangle.
- Only distinct rectangles should be counted.
Input: N = 3 Output: 1 . . . . . . . . . . The only triangle possible has the top edges at the two points of the second row and bottom edges at the 2nd and the 3rd points in the last row. Input: N = 5 Output: 11
Approach: From the above figure, it is clear that n and n – 1 level doesn’t contribute to make any rectangle, so we start to count rectangle from the n – 2 level. When n is odd and the level at which we are calculating say i is also odd then the difference will be even and so we divide it by 2. This will give us the number of vertical levels between the level n and i which can be used for making rectangles and this is same if both are even as difference of even numbers is even.
But when one of them is odd then difference will be odd and so n – 1 level will contribute in selecting vertical levels therefore n – 1 level is used in calculation. To calculate the number of ways by which the two dots can be selected in horizontal level we can use formula for sum of n natural numbers because NC2 = 1 + 2 + 3 + … + (N – 1). Now we multiply the number of ways of choosing two dots in one level by the number of dots in vertical level. This will be our result for that particular level and so we will repeat these steps till last and sum up all the values.
Below is the implementation of the above approach:
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Largest hexagon that can be inscribed within an equilateral triangle
- Area of circle which is inscribed in equilateral triangle
- Biggest Square that can be inscribed within an Equilateral triangle
- Count Distinct Rectangles in N*N Chessboard
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Time required to meet in equilateral triangle
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Program to calculate area and perimeter of equilateral triangle
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
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.