http://acm.hdu.edu.cn/showproblem.php?pid=2289
我的代码
1 #include <stdio.h>
2 #include <math.h>
3 double r1,r2,h,v;
4 const double pi=acos(-1.0),esp=1e-9;
5 double f(double x)
6 {
7 double r=(r2-r1)*x/h+r1;
8 return (r1*r1+r*r+r1*r)*pi*x/3;
9 }
10 int main()
11 {
12 int T;
13 double l,r,m;
14 scanf("%d",&T);
15 while (T--)
16 {
17 scanf("%lf%lf%lf%lf",&r1,&r2,&h,&v);
18 l=0; r=h;
19 while (fabs(l-r)>esp)
20 {
21 m=(l+r)/2;
22 if (v<f(m)) r=m;
23 else l=m;
24 }
25 printf("%.6lf\n",l);
26 }
27 }