三分 POJ3737
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 5 using namespace std; 6 7 double pi=acos(-1.0); 8 double s; 9 10 double f(double x) 11 { 12 return pi*x*x*sqrt((s-pi*x*x)/(pi*x)*(s-pi*x*x)/(pi*x)-x*x)/3; 13 } 14 15 bool test(double tl,double tr) 16 { 17 if(f(tl)<f(tr)) 18 return true; 19 else 20 return false; 21 } 22 23 int main() 24 { 25 while(scanf("%lf",&s)!=EOF) 26 { 27 double l=0; 28 double r=sqrt(s/(2*pi)); 29 while(r-l>1e-8) 30 { 31 double tl=l+(r-l)/3; 32 double tr=r-(r-l)/3; 33 if(test(tl,tr)) 34 { 35 l=tl; 36 } 37 else 38 { 39 r=tr; 40 } 41 } 42 double h=sqrt((s-pi*l*l)/(pi*l)*(s-pi*l*l)/(pi*l)-l*l); 43 printf("%.2lf\n",f(l)); 44 printf("%.2lf\n",h); 45 printf("%.2lf\n",l); 46 } 47 return 0; 48 }