题目: Cylinder
时间限制: 1Sec 内存限制: 128MB
题目描述
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.
输出
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
题目大意:
给你一张w宽和h长的长方形纸,切成两个长方形,其中一个用来切圆形,作为圆柱的地面;另一个作为圆柱的侧面,这个长方形中与圆形贴着的那一边,长度可以大于等于圆形的周长。
题目分析:
这是一个数学问题,倒没有什么算法上的模板、技巧什么的。
如图所示,这道题需要分两种情况考虑,然后取两种情况的最大值。
-
取H-2r作为圆形周长,取w作为圆柱体的高。
要满足2Πr<=H-2r,
得到r最大值H/[2*(Π+1)]
然后计算体积。
**注意!**如果算下最大值r要大于w的一半,我们就必须令r取w/2,然后判断r的取值是否合理,也就是h-2r是否小于2Πr,即h-w是否小于Πw,若不满足,直接返回0. -
取W作为圆形周长,取H-2r作为圆柱的高
满足2Πr<=w
得到r的最大值w/2Π
然后计算出体积
注意这种情况是一定满足条件的,因为求最大值r就是在临界条件下求得的。 -
比较二者体积,输出最大值