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:
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.
- 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
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Biggest Square that can be inscribed within an Equilateral triangle
- Area of circle which is inscribed in equilateral triangle
- Largest hexagon that can be inscribed within an equilateral triangle
- Area of Equilateral triangle inscribed in a Circle of radius R
- Maximum area of rectangle inscribed in an equilateral triangle
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Program to calculate area and perimeter of equilateral triangle
- Time required to meet in equilateral triangle
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
- Area of Circumcircle of an Equilateral Triangle using Median
- Program To Check whether a Triangle is Equilateral, Isosceles or Scalene
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.