UmBasketella POJ - 3737

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leekerian/article/details/82668582

三分

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;
const double eps=1e-8;


double S;
const double PI=acos(-1.0);

double f(double x)
{
    double ans=sqrt((S/(PI*x)-x)*(S/(PI*x)-x)-x*x)*PI*x*x/3.0;
    return ans;
}
int main()
{
    while(scanf("%lf",&S)!=EOF)
    {
        double l=0.0;
        double r=sqrt(S/PI);
        while(r-l>eps)
        {
            double lmid=l+(r-l)/3;
            double rmid=r-(r-l)/3;
            if(f(lmid)>=f(rmid))
                r=rmid;
            else
                l=lmid;
        }
        printf("%.2lf\n",f(l));
        printf("%.2lf\n",sqrt((S/(PI*l)-l)*(S/(PI*l)-l)-l*l));
        printf("%.2lf\n",l);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/leekerian/article/details/82668582
POJ