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.

输出

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

题目思路

题目大概:将一张纸剪成两张,剪线与短边平行,做出体积最大的圆柱。
在这里插入图片描述

c语言AC代码

#include <stdio.h>
#define pi 3.14159265358
double volume(double w,double h)
{	
	double temp,r1=0,r2=0,v1=0,v2=0;
	//第一种情况,以h-2r为周长,以w为高 
	r1=h/(2*pi+2);
	r1=r1*2>w?w/2:r1;
	v1=pi*r1*r1*w;
	//第二种情况,以h-2r为高,以w为周长 
	r2=w/(2*pi);
	v2=pi*r2*r2*(h-2*r2);
	if(v1>v2)//比较两种情况下哪一种的体积最大 
		return v1;
	else return v2;
}
int main()
{
	double w,h,v=0;
	while(scanf("%lf%lf", &w, &h) ==2&&w!= 0)
	{
		v=volume(w,h);
		printf("%.3f\n",v);
	}
	return 0;
 } 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@玉面小蛟龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值