📜  可围绕大小为LxW的给定矩形外接的矩形的最大面积

📅  最后修改于: 2021-05-06 22:24:12             🧑  作者: Mango

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

例子:

方法:下面是给定的尺寸LW的矩形EFGH 。我们必须找到包围ABCD矩形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


输出:
450.0

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