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=PI*r*l+PI*r*r;
v=1/3*PI*r*r*h;
我的三分是很中规中矩的三分。
我的思路是将圆锥地步的半径r作为变量来确定最大面积;
所以low和high是r的取值范围,low肯定是取0,high取sqrt((s/2)/PI)。
为什么high = sqrt((s/2)/PI)呢?
因为当r最大这种极限情况就是圆锥的高无限接近0的时候,所以相当与两个圆叠在一起。所s/2就是其中一个圆的面积,如何通过圆面积公式算出r。故high = sqrt((s/2)/PI);
solve(double r)就是给一个底面半径算出体积;
最后三分出结果。
[代码]
#include<cstdio>
#include<cmath>
using namespace std;
double PI;
const double eps = 1e-6;
double s;
double max;
double solve(double r)
{
//s=PI*r*l+PI*r*r;
//v=1/3*PI*r*r*sqrt(l*l-r*r);
double l = s / (PI*r) - r;
double h = sqrt(l*l - r*r);
return 1.0 / 3.0*PI*r*r*h;
}
int main()
{
PI=acos(-1.0);
while (scanf("%lf", &s)!=EOF)
{
double low = 0, high = sqrt((s/2)/PI);
max = high;
double mid, midmid;
while (low + eps < high)
{
mid = (low + high) / 2.0;
midmid = (mid + high) / 2.0;
double vmid = solve(mid);
double vmidmid = solve(midmid);
if (vmid > vmidmid)high = midmid;
else low = mid;
}
double l = s / (PI*low) - low;
printf("%.2lf\n%.2lf\n%.2lf\n", solve(low), sqrt(l*l - low*low),low);
}
}