精度小一点就能过
#include<bits/stdc++.h>
#define maxn 1000000009
#define esp 1e-9
#define PI 3.1415926535897932384626
using namespace std;
double r,R,H,V,V1,h1,R1;
double func(
double h1){
R1=r+(h1/H)*(R-
r);
V1=((
double)
1/
3)*PI*h1*(R1*R1+r*r+R1*
r);
return V1;
}
int main(){
int t;
scanf("%d",&
t);
while(t--
){
scanf("%lf%lf%lf%lf",&r,&R,&H,&
V);
double ll=
0,rr=
H;
while(abs(rr-ll)>
esp){
h1=(ll+rr)/
2;
if(func(h1)<
V)
ll=
h1;
else rr=
h1;
}
printf("%.6lf\n",(ll+rr)/
2);
}
}
转载于:https://www.cnblogs.com/zsben991126/p/10144344.html
相关资源:各显卡算力对照表!