joj 2575: Moveable quadrangle with three edges ()

    技术2022-05-20  55

    ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE3s8192K43575Standard

    我们知道,四边形是可以移动和不稳定的。给定三个相连的边a,b和c,它们之间的夹角可以活动,第四条边由两边的顶点虚拟连线构成,这个四边形的面积随不同的夹角变化。请找出最大的四边形面积。

    Input

    输入的每一行代表一个Case。每一行有三个正浮点数,分别是a,b,c。

    Output

    对于每一个输入,计算最大的四边形的面积。输入四舍五入到小数点后4位。

    Sample Input

    1 1 1.0 1 2 1.0

    Sample Output

    1.2990 2.2018 /* 利用几何关系找到当a b夹角固定时,c应当与ab边所成三角形垂直时,面积最大,所以只需枚举a b夹角就好(数据很水)。 */

    #include <cstdio>

    #include <iostream>

    #include <memory>

    #include <cmath>

    const int maxn = 1000;

    const double pi=acos(-1.);

    const double p=1e-5;

    int main ()

    {

        double a,b,c;

        while (scanf("%lf%lf%lf",&a,&b,&c)!=EOF)

        {

        double ans=0,r,tmp;

        for ( r=p ; r<pi ; r=r+p)

        {

            double d=sqrt(a*a+b*b-2*a*b*cos(r));

             tmp = a*b*sin(r)/2+d*c/2 ;

            if(ans<tmp)ans=tmp;

        }

        printf("%.4lf/n",ans);

        }

        return 0;

    }


    最新回复(0)