HDU - 2289 CUP

简单题,没啥好说的。。
数学公式。。相似

#include<stdio.h>
#define pi 3.14159265358
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        double r1,r2,hc,vw;
        scanf("%lf%lf%lf%lf",&r1,&r2,&hc,&vw);
        double left=0;
        double right=hc;
        double mid;
        while(right-left>0.0000000001)
        {
            mid=(left+right)/2;
            double newr=r1-(r1-r2)*mid/hc;
            double v=pi*mid*(r1*r1+newr*newr+r1*newr)/3;
            if(v>vw)
                right=mid;
            else
                left=mid;
        }
        printf("%.6lf\n",right);

    }
    return 0;
}

你可能感兴趣的:(hdu-二分)