Janitor Troubles Gym - 102007J —— 4条线段构成最大的四边形面积

J Janitor Troubles Time limit: 1s
While working a night shift at the university as a janitor,
you absent-mindedly erase a blackboard covered with
equations, only to realize afterwards that these were no
ordinary equations! They were the notes of the venerable
Professor E. I. N. Stein who earlier in the day solved the
elusive maximum quadrilateral problem! Quick, you have
to redo his work so no one noticed what happened.
The maximum quadrilateral problem is quite easy to state: given four side lengths s1, s2, s3
and s4, find the maxiumum area of any quadrilateral that can be constructed using these
lengths. A quadrilateral is a polygon with four vertices.
Input
The input consists of a single line with four positive integers, the four side lengths s1, s2, s3,
and s4.
It is guaranteed that 2si <
P4
j=1 sj , for all i, and that 1 ≤ si ≤ 1000.
Output
Output a single floating point number, the maximal area as described above. Your answer
must be accurate to an absolute or relative error of at most 10−6
.
Sample Input 1 Sample Output 1
3 3 3 3 9
Sample Input 2 Sample Output 2
1 2 1 1 1.299038105676658
Sample Input 3 Sample Output 3
2 2 1 4 3.307189138830738

题意:

给你4条线段,求这4条线段能组成的四边形面积最大是多少。

题解:

一开始的时候只想到了有一个角是90度,但是最大的应该是两个叫都是90度,这就是求最大外接圆的时候的面积,公式就是

#include
using namespace std;
int main()
{
    double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    double p=(a+b+c+d)/2;
    printf("%.15f\n",sqrt((p-a)*(p-b)*(p-c)*(p-d)));
    return 0;
}

你可能感兴趣的:(数学)