2018hdu个人排位赛:Stadium

2018hdu个人排位赛:Stadium_第1张图片

给四个数,看看能否构成梯形,能的话求出最小面积

(好像给的数据直接就是能够成梯形的)

#include
using namespace std;
int t,a[4];
double m;
double f(double a,double b,double c,double d)
{
    double C=b-a;
    double x=(d*d+C*C-c*c)/(2*C);
    if(d*d-x*x<0)
        return 0;
    double h=sqrt(d*d-x*x);
    return (a+b)*h/2;
}
int main()
{
    scanf("%d",&t);
    while(t--&&scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]))
    {
        sort(a,a+4);
        if(a[0]+a[1]+a[2]<=a[3])
        {
            puts("IMPOSSIBLE");
            continue;
        }
        m=f(a[0],a[1],a[2],a[3]);//全排列,寻找面积最小值
        m=max(m,f(a[0],a[2],a[1],a[3]));
        m=max(m,f(a[0],a[3],a[1],a[2]));
        m=max(m,f(a[1],a[2],a[0],a[3]));
        m=max(m,f(a[1],a[3],a[0],a[2]));
        m=max(m,f(a[2],a[3],a[0],a[1]));
        printf("%.2f\n",m);
    }
}

你可能感兴趣的:(hdu)