给定四个正整数A 、 B 、 C和D表示循环四边形的边长,任务是找到循环四边形的面积。
例子:
Input: A = 10, B = 15, C = 20, D = 25
Output: 273.861
Input: A = 10, B = 30, C = 50, D = 20
Output: 443.706
方法:根据以下观察可以解决给定的问题:
- 循环四边形是顶点都在一个圆上的四边形。圆称为外接圆或外接圆,顶点称为同环。
- 在上图中, r是外接圆的半径, A 、 B 、 C和D分别是边PQ 、 QR 、 RS和SP的长度。
- 四边形的面积由Bretschneider 公式给出:
where, A, B, C, and D are the sides of the triangle and
α and γ are the opposite angles of the quadrilateral.
Since, the sum of opposite angles of the quadrilateral is 180 degree. Therefore, the value of cos(180/2) = cos(90) = 0.
Therefore, the formula for finding the area reduces to .
因此,想法是打印的值作为给定四边形的合成面积。
下面是上述方法的实现:
C++
// C++ programm for the above approach
#include
using namespace std;
// Function to find the area
// of cyclic quadrilateral
float calculateArea(float A, float B,
float C, float D)
{
// Stores the value of
// half of the perimeter
float S = (A + B + C + D) / 2;
// Stores area of cyclic quadrilteral
float area = sqrt((S - A) * (S - B)
* (S - C) * (S - D));
// Return the resultant area
return area;
}
// Driver Code
int main()
{
float A = 10;
float B = 15;
float C = 20;
float D = 25;
cout << calculateArea(A, B, C, D);
return 0;
}
Java
// Java program for the above approach
import java.io.*;
class GFG{
// Function to find the area
// of cyclic quadrilateral
static float calculateArea(float A, float B,
float C, float D)
{
// Stores the value of
// half of the perimeter
float S = (A + B + C + D) / 2;
// Stores area of cyclic quadrilteral
float area = (float)Math.sqrt((S - A) * (S - B) *
(S - C) * (S - D));
// Return the resultant area
return area;
}
// Driver code
public static void main (String[] args)
{
float A = 10;
float B = 15;
float C = 20;
float D = 25;
System.out.println(calculateArea(A, B, C, D));
}
}
// This code is contributed by Ankita saini
Python3
# Python3 programm for the above approach
from math import sqrt
# Function to find the area
# of cyclic quadrilateral
def calculateArea(A, B, C, D):
# Stores the value of
# half of the perimeter
S = (A + B + C + D) // 2
# Stores area of cyclic quadrilteral
area = sqrt((S - A) * (S - B) *
(S - C) * (S - D))
# Return the resultant area
return area
# Driver Code
if __name__ == '__main__':
A = 10
B = 15
C = 20
D = 25
print(round(calculateArea(A, B, C, D), 3))
# This code is contributed by mohit kumar 29
C#
// C# program for the above approach
using System;
class GFG{
// Function to find the area
// of cyclic quadrilateral
static float calculateArea(float A, float B,
float C, float D)
{
// Stores the value of
// half of the perimeter
float S = (A + B + C + D) / 2;
// Stores area of cyclic quadrilteral
float area = (float)Math.Sqrt((S - A) * (S - B) *
(S - C) * (S - D));
// Return the resultant area
return area;
}
// Driver Code
static public void Main()
{
float A = 10;
float B = 15;
float C = 20;
float D = 25;
Console.Write(calculateArea(A, B, C, D));
}
}
// This code is contributed by code_hunt
Javascript
输出:
273.861
时间复杂度: O(1)
辅助空间: O(1)
如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程和学生竞争性编程现场课程。