标签:
题意:给出圆台的底面半径,顶部半径,高还有水的体积,求水的高度思路:我们可以直到水的高度必然在0到最大高度之间,在这个区间内进行二分即可#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define PI acos(-1.0) #define exp 1e-9 double solve(double r,double R,double h,double H){ double u = h/H*(R-r) + r; return PI/3*(r*r+r*u+u*u)*h; } int main() { int t; double r,R,H,V,mid,vv,f,l; scanf("%d",&t); while(t--){ scanf("%lf%lf%lf%lf",&r,&R,&H,&V); f=0; l=100; while(l-f>exp){ mid=(l+f)/2; vv=solve(r,R,mid,H); if(fabs(vv-V)<=exp) break; else if(vv>V) l = mid - exp; else f = mid + exp; } printf("%.6lf\n",mid); } return 0; }
标签:
原文地址:http://blog.csdn.net/a197p/article/details/46352181