Problem K: Cylinder

Problem K: Cylinder

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 17   Solved: 7
[ Submit][ Status][ Web Board]

Description

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? 


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

这一题的主要意思就是给你一张纸,让你剪成两半,一张留着做底一张留着做身,问这个圆筒最大的容积!

注意精度问题就可以了!不注意WA不知道原因

#include<stdio.h>
#define PI 3.141592653589
double area(double x,double y)
{
	//以x为园的周长
	double r,s,v;
	r=x/(PI*2);
	s=PI*r*r;
	v=s*(y-x/PI);
	return v; 
}
int main()
{
	double w,h,v1,v2,r,r1,s;
	while(scanf("%lf%lf",&w,&h)&&(w||h))
	{
		//x为圆的高
		r1=h/(PI+1)/2;
		if(r1>w/2)
		{
			r=w/2;
		}
		else
		{
			r=r1;
		}
		s=PI*r*r;
		v1=s*w;
		v2=area(w,h);
        if(v1>v2)
		{
			printf("%.3lf\n",v1);
		}
		else
		{
			printf("%.3lf\n",v2);
		}

	}
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值