# [POJ 3737] UmBasketella【三分查找】

## Problem:

Time Limit: 1000MS |
Memory Limit: 65536K |

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

Source

## Solution:

在 [0, sqrt(S/2π)] 上三分查找半径 r，采用三等分法计算即可。

注意精度 eps 要设置得足够小，可以采用 1e-12。

还有要把 π 的值背出十几位，如 3.141592653589793...

## Code: O(Tlog_{3}(S/ε)) [192K, 0MS]

#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define eps 1e-12 #define PI 3.141592653589793 using namespace std; inline int dsgn(double x){ if(fabs(x) <= eps) return 0; return x < 0 ? -1 : 1; } double S; inline double height(double r){ double l = S / PI / r - r; return sqrt(l * l - r * r); } inline double volume(double r){ double h = height(r); return PI * r * r * h / 3; } int main(){ while(scanf("%lf", &S) != EOF){ double lft = 0, rt = sqrt(S / 2 / PI); while(dsgn(lft - rt) < 0){ double lmid = lft + (rt - lft) / 3, rmid = rt - (rt - lft) / 3; if(dsgn(volume(lmid) - volume(rmid)) < 0) lft = lmid; else rt = rmid; } double h = height(lft), v = volume(lft); printf("%.2f\n%.2f\n%.2f\n", v, h, lft); } return 0; }

## 发表评论