POJ 3737 UmBasketella(三分)

来源:互联网 发布:什么是网络教学 编辑:程序博客网 时间:2024/05/18 20:08

UmBasketella

Description

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
题目大意:给出一个圆锥的表面积(侧面积 + 底面积),求这个圆锥的最大体积、高度和底面半径。

解题思路:圆锥表面积S = πrl + πr ^ 2,体积V = (1 / 3) * hπr ^ 2,由数学知识可以将l和h用r表示出来,进而得到体积关于底面半径的表达式,这是一个单峰函数,三分半径可以得到答案。(PS:因为编译器的原因WA了一上午,G++WA,换成C就AC了)

代码如下:

#include<cstdio>#include<cmath>#define eps 1e-8#define PI acos(-1.0)double s;double getH(double r){    double l = s / (PI * r) - r;return sqrt(l * l - r * r);}double getV(double r){double h = getH(r);return PI * r * r * h / 3;}int main(){    while(scanf("%lf",&s) != EOF)    {        double lb,ub,lm,um;        lb = 0;        ub= sqrt(s / PI / 2);        while(ub - lb > eps)        {            lm = (lb + ub) / 2;            um = (lm + ub) / 2;            if(getV(lm) > getV(um))                ub = um;            else                lb = lm;        }        printf("%.2f\n%.2f\n%.2f\n",getV(lb),getH(lb),lb);    }    return 0;}


0 0
原创粉丝点击