2013
12-23

# Cylinder

Using a sheet of paper and scissors, you can cut out two faces to form a cylinder in the following way:

1. Cut the paper horizontally (parallel to the shorter side) to get two rectangular parts.
2. From the first part, cut out a circle of maximum radius. The circle will form the bottom of the cylinder.
3. Roll the second part up in such a way that it has a perimeter of equal length with the circle’s circumference, and attach one end of the roll to the circle. Note that the roll may have some overlapping parts in order to get the required length of the perimeter.
Given the dimensions of the sheet of paper, can you calculate the biggest possible volume of a cylinder which can be constructed using the procedure described above?

The input consists of several test cases. Each test case consists of two numbers w and h (1 ≤ w ≤ h ≤ 100), which indicate the width and height of the sheet of paper.

The last test case is followed by a line containing two zeros.

For each test case, print one line with the biggest possible volume of the cylinder. Round this number to 3 places after the decimal point.

10 10
10 50
10 30
0 0

54.247
785.398
412.095

Hint
In the first case, the optimal cylinder has a radius of about 1.591549,
in the second case, the optimal cylinder has a radius of 5,
and in the third case, the optimal cylinder has a radius of about 3.621795.


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
double PI = acos(-1);
double Min(double a, double b)
{
return a < b ? a : b;
}
double Max(double a, double b)
{
return a > b ? a : b;
}
int main()
{
double w, h, r, ans1, ans2, ans;
while (scanf("%lf%lf", &w, &h) != EOF && w &&h)
{
r = Min(w / 2.0, h /(2.0 * PI + 2.0));//以w为圆柱的高
ans1 = PI * r * r * w;
r = Min(w / (2.0 * PI), h / 3.0);
ans2 = PI * r * r * (h - 2.0 * r);//以h-2r为圆柱的高
ans = Max(ans1, ans2);
printf("%.3lf\n", ans);
}
return 0;
}