Cylinder——蓝桥杯提高题

题目: 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长的长方形纸,切成两个长方形,其中一个用来切圆形,作为圆柱的地面;另一个作为圆柱的侧面,这个长方形中与圆形贴着的那一边,长度可以大于等于圆形的周长。

题目分析:
这是一个数学问题,倒没有什么算法上的模板、技巧什么的。

长方形纸片
如图所示,这道题需要分两种情况考虑,然后取两种情况的最大值。

  1. 取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.

  2. 取W作为圆形周长,取H-2r作为圆柱的高
    满足2Πr<=w
    得到r的最大值w/2Π
    然后计算出体积
    注意这种情况是一定满足条件的,因为求最大值r就是在临界条件下求得的。

  3. 比较二者体积,输出最大值

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值