here is my code

Code: Select all

```
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
using namespace std;
const double err=0.001;
const double pi=acos(-1.0);
double S(double r,double t){
double a=2*acos((r-t)/r);
double s=0.5*r*r*(a-sin(a));
return s;
}
double VCyl(double R,double h,double t){
double ret;
ret=S(R,t)*h;
return ret;
}
double VCone(double R,double h,double t){
double ret,h1;
if (R>=t)
{
h1=t*h/R;
ret=S(R,t)*h1/3.0;
}
else
{
t=2*R-t;
h1=t*h/R;
double s=S(R,t);
ret=pi*R*R*h/3.0-s*h1/3.0;
}
return ret;
}
double VConehalf(double R,double r,double h, double t){
double h1=(r*h)/(R-r);//kichik konusning balndligi, h esa orasidagi balandlik
double Vkichik;
double Vkatta=VCone(R,h1+h,t);
if (t<(R-r)) Vkichik=0.0;
else if (t<(R+r))
Vkichik=VCone(r,h1,t+r-R);
else Vkichik=pi*r*r*h1/3.0;
double ret=Vkatta-Vkichik;
return ret;
}
double Volume(double R,double r,double h1, double h2,double h3,double t){
double vcyl_katta=VCyl(R,h1,t);
double vcon=VConehalf(R,r,h2,t);
double vcyl_kichik;
if (t<(R-r)) vcyl_kichik=0.0;
else if (t<(R+r))
vcyl_kichik=VCyl(r,h3,t+r-R);
else vcyl_kichik=pi*r*r*h3;
double ret=vcyl_katta+vcon+vcyl_kichik;
return ret;
}
double bisearch(double R,double r,double h1,double h2,double h3,
double V,double left,double right){
double mid=(left+right)/2.0,ret;
if (fabs(right-left)<0.01)
return mid;
double Vol=Volume(R,r,h1,h2,h3,mid);
if (fabs(V-Vol)<err) return mid;
if (V<Vol){
ret=bisearch(R,r,h1,h2,h3,V,left,mid);
}
else
{
ret=bisearch(R,r,h1,h2,h3,V,mid,right);
}
return ret;
}
double allV;
int main(){
freopen("a.in","r",stdin);
double k,hb,db,hn,dn,h;
//k=3.592; printf("%.2f\n\n",k);
double H,h1,h2,h3,R,r,V,a,b,r1;
while(1){
cin>>k>>hb>>db>>hn>>dn>>h;
if (int(k+hb+db+hb+dn+h)==0) break;
H=h; h1=hb; h3=hn; h2=H-h1-h3;
R=db/2.0; r=dn/2.0; r1=(h1+h2-k)*R/h2;
if (k<=h1) V=pi*R*R*k;
else if (k<=h1+h2) V=pi*R*R*h1+pi*(k-h1)*(R*R+R*r1+r1*r1)/3;
else V=pi*R*R*h1+pi*h2*(R*R+R*r+r*r)/3.0+pi*r*r*(k-h1-h2);
allV=pi*R*R*h1+pi*h2*(R*R+R*r+r*r)/3.0+pi*r*r*h3;
double t=bisearch(R,r,h1,h2,h3,V,0.0,2*R);
assert(((int)t)!=-1);
printf("%.2f\n",t);
}
return 0;
}
```