[POJ3737]UmBasketella

来源:互联网 发布:小漠鞋子淘宝店 编辑:程序博客网 时间:2024/05/29 05:06

In recent days, people always design new things with multifunction. For instance, you can not only use cell phone to call your friends, but you can also use your cell phone take photographs or listen to MP3. Another example is the combination between watch and television. These kinds of multifunction items can always improve people's daily life and are extremely favored by users.

The company Mr. Umbrella invented a new kind umbrella "UmBasketella" for people in Rainbow city recently and its idea also comes from such multifunction--the combination of umbrella and daily necessities. This kind of umbrella can be used as a basket and you can put something you want to carry in it. Since Rainbow city rains very often, such innovative usage is successful and "UmBasketella" sells very well. Unfortunately, the original "UmBasketella" do not have an automatic volume control technology so that it is easily damaged when users try to put too many things in it. To solve this problem, you are needed to design an "UmBasketella" with maximum volume. Suppose that "UmBasketella" is a cone-shape container and its surface area (include the bottom) is known, could you find the maximum value of the cone?

Input

Input contains several test cases. Eash case contains only one real number S, representing the surface area of the cone. It is guaranteed that 1≤S≤10000.

Output

For each test case, output should contain three lines.
The first line should have a real number representing the maximum volume of the cone. 
Output the height of the cone on the second line and the radius of the bottom area of the cone on the third line.
All real numbers should rounded to 0.01.

Sample Input
30
Sample Output
10.934.371.55

题意:给出一个圆锥的表面积(包括底面积),求出它的最大体积及此时的高和底面半径

题解:用三分法求底面半径, 再缩小范围
母线长: l = sqrt( h^2+r^2 )
圆锥表面积: S = pi*r^2 + ( r/l )*pi*l^2 = pi*r^2 + r*pi*l = pi*r*( r+l )
高度: h = sqrt( ( S/( pi*r ) )^2 - 2*S/pi )
体积: V = 1/3*pi*r^2*h

当然也可以直接用纯数学方法解决:http://blog.csdn.net/qq_37816449/article/details/75150906

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const double eps=1e-7;const double pi=3.1415926535898;double S;double height( double r ) {double h=( S/( pi*r ) )*( S/( pi*r ) ) - 2*S/pi;if( h<0 ) return -1;//h可能小于0return sqrt( h );}int main() {while( ~scanf( "%lf", &S ) ) {double downr=0, upr=sqrt( S/pi/2 );double Vl, Vr;while( upr-downr>eps ) {double midl=( downr+upr )/2;double midr=( midl+upr )/2;Vl=height( midl );Vr=height( midr );Vl=pi*midl*midl*Vl/3;Vr=pi*midr*midr*Vr/3;if( Vl>Vr ) upr=midr;else downr=midl;}printf( "%.2lf\n%.2lf\n%.2lf\n", Vl, height( upr ), upr );}return 0;}


原创粉丝点击