cylinder体积公式_SDUT 2374 || HDU 1803Cylinder(计算几何求体积)

Cylinder

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 224    Accepted Submission(s): 88

Problem Description

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?

Input

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.

Output

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.

Sample Input

10 10

10 50

10 30

0 0

Sample Output

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.

Source

2007~2008 University of Ulm Local Contest

结题报告:这道题的题意是求圆柱的最大体积,当时内部比赛时看错题意了,以为是封闭的圆柱呢!哎!但是真正题意是圆柱没有上盖;给我们一张纸,w, h(h > w);平行于w把这张纸分成两半,一半画一个圆,另一部分当圆柱的侧面,分两种情况,第一种情况是让w当高,其半径为应满足2*PI*r <= h- 2r,并且w >= 2 * r即:r=w/2或h/(2*PI + 2)中选出最小的;第二种情况是让h-2*r当高,极限情况下V= (h- 2* r) * PI* r*r,求导后r=h/3并且还得满足w>= 2*PI*r;r应去最小的情况;

代码如下:

#include

#include

#include

#include

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;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值