POJ 3737 UmBasketella 三分或公式

UmBasketella
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7955 Accepted: 3006

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

题意:给出一个圆锥的表面积,求这个圆锥的最大体积,以及最大体积时候的高和底面半径。

解法一:当圆锥底面积是表面积1/4时,圆锥有最大体积,推导:点击打开链接

解法二:三分底面半径,根据高中立体几何的经验,冥冥中有种感觉它的体积与底面半径关系满足单峰凸形函数,遂三分试了一下,能过。

三分用三个公式就好了:

1.母线与底面半径高关系R*R+H*H=L*L 

2.表面积公式S = PI*R*L+PI*R*R 3.

3.体积公式V = PI*R*R*H/3


解法一CODE:

#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1);
int main()
{
    double S;
    while(scanf("%lf",&S)!=EOF){
        double r = sqrt(S/4/PI);
        double l = (S-PI*r*r)/(PI*r);
        double h = sqrt(l*l-r*r);
        double v = PI*r*r*h/3;
        printf("%.2f\n%.2f\n%.2f\n",v,h,r);
    }
    return 0;
}
解法二CODE:

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1);
int main(void)
{
    double S;
    while(scanf("%lf",&S) != EOF){
        double ansr,ansh,ansv;
        double l = 0,r = sqrt(S/PI/1.2); ///r是根据表面积公式试出来的比较小的上限
        while(fabs(l-r) > 1e-8){
            double m = (l+r)/2;
            double mm = (r+m)/2;
            double mL = (S-PI*m*m)/(PI*m);
            double mH = sqrt(mL*mL-m*m);
            double mV = PI*m*m*mH/3;
            ansr = m,ansh = mH,ansv = mV;
            double mmL = (S-PI*mm*mm)/(PI*mm);
            double mmH = sqrt(mmL*mmL-mm*mm);
            double mmV = PI*mm*mm*mmH/3;
            if(mV > mmV) r = mm;
            else l = m;
        }
        printf("%.2f\n%.2f\n%.2f\n",ansv,ansh,ansr);
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值