1. 程式人生 > >【三分】POJ - 3737 R - UmBasketella

【三分】POJ - 3737 R - UmBasketella

POJ - 3737  R - UmBasketella 

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.93
4.37
1.55

給你一個表面積S,問你h,r取多少時,這個圓錐形物體能得到表面積(包括底面積)<=S且體積最大

三分半徑求答案

整體很簡單

最討厭的就是l,r的取值有講究

需要l小,而r把h當做0的話,S=2*PI*r*r,那麼r為sqrt(S/2,0/PI)

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-4;
const double PI=acos(-1);
double S;
double cal(double r)
{
    double s=S;
    s=(s-PI*r*r)/(PI*r);
    s=s*s-r*r;
    double h=sqrt(s);
    return PI*r*r*h/3;
}

int main()
{
    //cin>>S;
    //cout<<cal(1.00)<<endl;
    while(~scanf("%lf",&S))
    {
        double l=0.1,r=sqrt(S/PI/2.0);
        double ans=0.0,h,R;
        while(l+eps<=r)
        {
            double mid=(l+r)/2;
            double midd=(mid+r)/2;
            if(cal(mid)>cal(midd)) r=midd;
            else l=mid;
            if(ans<cal(l))
            {
                ans=cal(l),R=l,h=ans*3/(PI*R*R);
            }
        }
        printf("%.2f\n%.2f\n%.2f\n",ans,h,R);
    }
    return 0;
}