题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289
#include <stdio.h>
#include <math.h>
#define EPS 1e-8
const double PI=3.14159265;
double r,R,H,V;
double Cal(double x)
{
double r0=(R-r)*x/H+r;
return PI*x*(r*r+r0*r0+r*r0)/3.0;
}
int main()
{
int test;
double left,right,mid;
scanf("%d",&test);
while(test--)
{
scanf("%lf %lf %lf %lf",&r,&R,&H,&V);
left=0.0,right=H;
while(right-left>EPS)
{
mid=(right+left)/2.0;
if(Cal(mid)-V>EPS)
right=mid;
else
left=mid;
}
printf("%.6lf\n",mid);
}
return 0;
}