📌  相关文章
📜  矩形的最大面积可以外接给给定的大小为 LxW 的矩形

📅  最后修改于: 2021-10-26 05:16:11             🧑  作者: Mango

给定一个尺寸为LW的矩形。任务是找到一个矩形的最大面积,该矩形可以围绕一个给定的尺寸为LW 的矩形。

例子:

方法:下面是尺寸LW的给定矩形EFGH 。我们必须找到外接矩形EFGH的矩形ABCD的面积。

在上图中:
如果\angle ABC = X 然后\angle CGF = 90 - X 因为 GCF 是直角三角形。
所以,
\angle HGD = 180 - \angle FGH - \angle CGF
=> \angle HGD = 180 - 90 - (90 - X)
=> \angle HGD = X
相似地,
\angle EHA = X
\angle FEB = X
现在,矩形 ABCD 的面积由下式给出:

将上述投影的值代入等式(1),我们有:

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
using namespace std;
 
// Function to find area of rectangle
// inscribed another rectangle of
// length L and width W
double AreaofRectangle(int L, int W)
{
     
    // Area of rectangle
    double area = (W + L) * (W + L) / 2;
     
    // Return the area
    return area;
}
 
// Driver Code
int main()
{
     
    // Given dimensions
    int L = 18;
    int W = 12;
     
    // Function call
    cout << AreaofRectangle(L, W);
    return 0;
}
 
// This code is contributed by Princi Singh


Java
// Java program for the above approach
import java.io.*;
import java.util.*;
 
class GFG{
     
// Function to find area of rectangle
// inscribed another rectangle of
// length L and width W
static double AreaofRectangle(int L, int W)
{
     
    // Area of rectangle
    double area = (W + L) * (W + L) / 2;
     
    // Return the area
    return area;
}
     
// Driver Code
public static void main(String args[])
{
     
    // Given dimensions
    int L = 18;
    int W = 12;
     
    // Function call
    System.out.println(AreaofRectangle(L, W));
}
}
 
// This code is contributed by offbeat


Python3
# Python3 program for the above approach
 
# Function to find area of rectangle
# inscribed another rectangle of
# length L and width W
def AreaofRectangle(L, W):
   
  # Area of rectangle
  area =(W + L)*(W + L)/2
 
# Return the area
  return area
 
# Driver Code
if __name__ == "__main__":
 
  # Given Dimensions
  L = 18
  W = 12
 
  # Function Call
  print(AreaofRectangle(L, W))


C#
// C# program for the above approach
using System;
 
class GFG{
     
// Function to find area of rectangle
// inscribed another rectangle of
// length L and width W
static double AreaofRectangle(int L, int W)
{
     
    // Area of rectangle
    double area = (W + L) * (W + L) / 2;
     
    // Return the area
    return area;
}
     
// Driver Code
public static void Main(String []args)
{
     
    // Given dimensions
    int L = 18;
    int W = 12;
     
    // Function call
    Console.Write(AreaofRectangle(L, W));
}
}
 
// This code is contributed by shivanisinghss2110


Javascript


输出:
450.0

时间复杂度: O(1)
辅助空间: O(1)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程