poj 3737

原题:

UmBasketella
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3988 Accepted: 1507

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.93
4.37
1.55
说白了就是已知圆锥的表面积,求其最大体积和在该体积的情况下,圆锥对应的高和半径。先列出圆锥
的体积函数式:V=PI*r*r*h/3。很明显是一个非单调存在极值的凸函数,可以采用三分极值法来求解。由于
此题涉及到浮点数运算,因此要注意在两个极值点靠近的界限。同时,三分极值类的题目很强调函数的准确
性,有时往往理论上本应得出相同的结果在机上运行时却不同。我做的时候所用的函数由于有过多的sqrt
操作导致一直过不了sample,后来百度了才知道用最原始的函数就行了。。。囧。
    不多说了,以下是代码:
#include "stdio.h"
#include "math.h"
const double PI=acos(-1.0);
double anst1,anst2,r1,r2,rmid1,rmid2,hmid1,hmid2,s;
double cacul(double r)
{
return r*r;
}
double slove(double r,double &h)
{
double tmp;
tmp=cacul(s/(PI*r));
h=sqrt(tmp-2*s/PI);
return PI*r*r*h/3;
}
int main()
{
double r,h;
while(scanf("%lf",&s)==1)
{
   r1=0;
   r2=sqrt(s/PI);
   do
   {
    rmid1=r1+(r2-r1)/3;
    rmid2=r2-(r2-r1)/3;
    anst1=slove(rmid1,hmid1);
    anst2=slove(rmid2,hmid2);
    if(anst1>anst2)
    {
     r2=rmid2;
    }
    else
    {
     r1=rmid1;
    }
   }while(fabs(anst1-anst2)>0.000000001);
   printf("%.2lf/n%.2lf/n%.2lf/n",anst1,hmid1,rmid1);
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值