📜  可以在椭圆中刻出的最大矩形区域

📅  最后修改于: 2021-04-29 14:55:59             🧑  作者: Mango

给定一个椭圆,主轴长度为2a2b 。任务是找到可以在其中刻出的最大矩形区域。
例子

Input: a = 4, b = 3
Output: 24

Input: a = 10, b = 8
Output: 160

方法
令矩形的右上角具有坐标(x,y)
然后是矩形的面积A = 4 * x * y
现在,

下面是上述方法的实现:

C++
// C++ Program to find the biggest rectangle
// which can be inscribed within the ellipse
#include 
using namespace std;
 
// Function to find the area
// of the rectangle
float rectanglearea(float a, float b)
{
 
    // a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the rectangle
    return 2 * a * b;
}
 
// Driver code
int main()
{
    float a = 10, b = 8;
    cout << rectanglearea(a, b) << endl;
    return 0;
}


Java
// Java Program to find the biggest rectangle
// which can be inscribed within the ellipse
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
class GFG{
// Function to find the area
// of the rectangle
static float rectanglearea(float a, float b)
{
  
    // a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
  
    // area of the rectangle
    return 2 * a * b;
}
  
// Driver code
public static void main(String args[])
{
    float a = 10, b = 8;
    System.out.println(rectanglearea(a, b));
}
}


Python 3
# Python 3 Program to find the biggest rectangle
# which can be inscribed within the ellipse
 
#  Function to find the area
# of the rectangle
def rectanglearea(a, b) :
 
    # a and b cannot be negative
    if a < 0 or b < 0 :
        return -1
 
    # area of the rectangle
    return 2 * a * b
  
 
# Driver code    
if __name__ == "__main__" :
 
    a, b = 10, 8
    print(rectanglearea(a, b))
 
 
# This code is contributed by ANKITRAI1


C#
// C# Program to find the
// biggest rectangle which
// can be inscribed within
// the ellipse
using System;
 
class GFG
{
// Function to find the area
// of the rectangle
static float rectanglearea(float a,
                           float b)
{
 
    // a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the rectangle
    return 2 * a * b;
}
 
// Driver code
public static void Main()
{
    float a = 10, b = 8;
    Console.WriteLine(rectanglearea(a, b));
}
}
 
// This code is contributed
// by inder_verma


PHP


Javascript


输出:
160