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. Sample Input 30 Sample Output 10.93 4.37 1.55 Source |
[Submit] [Go Back] [Status] [Discuss]
题目大意:给出一个圆锥的面积,求圆锥的最大体积。
题解:三分
s=pi*r*r+pi*r*l
l=s/pi/r-r
h=sqrt(l*l-r*r)
v=pi*r*r*h/3
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define eps 1e-6
using namespace std;
double s,pi=acos(-1.0);
double calc(double r)
{
double l=s/pi/r-r;
double h=sqrt(l*l-r*r);
return pi*r*r*h/3.0;
}
int main()
{
while (scanf("%lf",&s)!=EOF){
double l=0; double r=s/pi;
while (r-l>eps){
double mid=(l+r)/2;
double midmid=(l+mid)/2;
if (calc(mid)>calc(midmid))
l=midmid+eps;
else r=mid-eps;
}
r=l;
l=s/pi/r-r;
double h=sqrt(l*l-r*r);
printf("%.2lf\n",pi*r*r*h/3.0);
printf("%.2lf\n",h);
printf("%.2lf\n",r);
}
}