给定两个整数A和B ,分别表示方程(x 2 / A 2 )+(y 2 / B 2 )= 1的椭圆的半长轴和半短轴的长度,任务是找到坐标轴与椭圆的任何切线所形成的三角形的最小面积。
例子:
Input: A = 1, B = 2
Output: 2
Input: A = 2, B = 3
Output: 6
方法:
该想法基于以下观察结果:上图中椭圆上的坐标(A *cosθ,B *sinθ)处的切线方程为:
(x * cosθ / A) + (y * sinθ / B) = 1
P和Q的坐标分别为(A /cosθ,0)和(0,B /sinθ) 。
由椭圆的切线和坐标轴形成的三角形的面积由下式给出:
Area of ΔOPQ = 0.5 * base * height = 0.5 * (A / cosθ) * (B / sinθ) = (A * B) / (2 * sinθ * cosθ) = (A * B) / sin2θ
Therefore, Area = (A * B) / sin2θ — (1)
为了使面积最小, sin2θ的值应为最大可能值,即1。
因此,最小可能面积为A * B。
下面是上述方法的实现:
C++
// C++ program for the above approach
#include
using namespace std;
// Function to find the minimum area
// of triangle formed by any tangent
// to ellipse with the coordinate axes
void minimumTriangleArea(int a, int b)
{
// Stores the minimum area
int area = a * b;
// Print the calculated area
cout << area;
}
// Driver Code
int main()
{
int a = 1, b = 2;
minimumTriangleArea(a, b);
return 0;
}
Java
// Java program for the above approach
class GFG{
// Function to find the minimum area
// of triangle formed by any tangent
// to ellipse with the coordinate axes
static void minimumTriangleArea(int a, int b)
{
// Stores the minimum area
int area = a * b;
// Print the calculated area
System.out.println(area);
}
// Driver Code
public static void main(String[] args)
{
int a = 1, b = 2;
minimumTriangleArea(a, b);
}
}
// This code is contributed by AnkThon
Python3
# Python3 program for the above approach
# Function to find the minimum area
# of triangle formed by any tangent
# to ellipse with the coordinate axes
def minimumTriangleArea(a, b):
# Stores the minimum area
area = a * b
# Print the calculated area
print(area)
# Driver Code
a = 1
b = 2
minimumTriangleArea(a, b)
# This code is contributed by rohitsingh07052
C#
// C# program for the above approach
using System;
class GFG{
// Function to find the minimum area
// of triangle formed by any tangent
// to ellipse with the coordinate axes
static void minimumTriangleArea(int a, int b)
{
// Stores the minimum area
int area = a * b;
// Print the calculated area
Console.WriteLine(area);
}
// Driver Code
public static void Main()
{
int a = 1, b = 2;
minimumTriangleArea(a, b);
}
}
// This code is contributed by ukasp
Javascript
// JavaScript program for the above approach
// Function to find the minimum area
// of triangle formed by any tangent
// to ellipse with the coordinate axes
function minimumTriangleArea(a, b)
{
// Stores the minimum area
var area = a * b
// Print the calculated area
console.log(area)
}
// Driver Code
var a = 1
var b = 2
minimumTriangleArea(a, b)
// This code is contributed by AnkThon
输出
2
时间复杂度: O(1)
辅助空间: O(1)