代码:
#include<bits/stdc++.h>
using namespace std;
double Pi=acos(-1.0);
double eps=1e-50;
double vd=0;
bool judge(double a,double b)//判断
{
return fabs(a-b)<eps;
}
double V(double a)//不是椭圆的体积
{
return Pi*cos(a)-a*cos(a)+sin(a)-pow(sin(a),3)/3;
}
double get(double seita){//a1=arccos(2tano-1) 求a1算体积;
double a1=acos(2*tan(seita)-1);
double v=(V(a1)-V(Pi))/tan(seita);
return v;
}
double solve(double l, double r){//二分找两个公式的解
int countt = 200;
if(judge(get(l),vd))
return l;
while(countt--){
double mid=(l+r)/2;
double gg=get(mid);
if(judge(gg, vd))
return mid;
if(gg > vd)
r = mid;
else
l = mid;
}
return l;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
double d;
scanf("%lf",&d);
vd=d*Pi;
if(judge(d, 0)){//判定零
printf("0.00000\n");
continue;
}
if(d-1>0){//判断大于一的情况
double seita=atan(2.0-d);
double ans=Pi/cos(seita);
printf("%.5f\n",ans);
continue;
}
//判断小于等于1的情况
double seita=solve(eps,Pi/4);
double a1=acos(2*tan(seita)-1);
double S1=Pi-a1+cos(a1)*sin(a1);
double ans=S1/sin(seita);
printf("%.5f\n", ans);
}
}