Cylinder
题目:
Using a sheet of paper and scissors, you can cut out two faces to form a cylinder in the following way:
Cut the paper horizontally (parallel to the shorter side) to get two rectangular parts.
From the first part, cut out a circle of maximum radius. The circle will form the bottom of the cylinder.
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.
翻译:
输入由多个测试用例组成。每个测试用例由两个数字 w 和 h(1 ≤ w ≤ h ≤ 100)组成,表示纸张的宽度和高度。
最后一个测试用例后跟一条包含两个零的行。
输出:
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.
翻译:
对于每个测试用例,打印一条具有最大可能体积的圆柱体的行。将此数字舍入到小数点后的 3 位。
例子
输入:
10 10
10 50
10 30
0 0
输出:
54.247
785.398
412.095
解析:
题目分为两大类,分别计算其体积取其大即可。
h-2r和w哪个是圆柱体的高并不确定,以两种情况分别讨论半径;
特别地,最大半径应该是较短边的一半,在以w为高时,如果2r>w则r=w/2应进行小类判断。
代码:
#include<stdio.h>
#define pi 3.1415926535898
int main()
{
double w,h,r,l,v1,v2,v;
while((scanf("%lf%lf",&w,&h)!=EOF&&w!=0&&h!=0))
{
r=w/(2*pi);
v1=pi*r*r*(h-2*r);
r=h/(2*pi+2);
if(2*r>w)
{
r=w/2;
}
v2=pi*r*r*w;
v=v1>v2?v1:v2;
printf("%.3lf\n",v);
}
return 0;
}