题目 1111: Cylinder

题目 1111: Cylinder

时间限制: 1Sec 内存限制: 128MB 提交: 1481 解决: 575

题目描述

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

ps:纸的长为length,宽为width,圆的直径为d,半径为r

简单的一道题,不过自己想当然了,对纸的分割不是用均分,分出来的圆的部分可能与剩下的纸构不成圆柱。

对于思路就可以想成是一个纸,然后有一道切割线分成两部分,从0开始分,分的长度是d,从左向右分割。

因此这个圆的直径d就可以从0到width。

1.如果圆的周长小于等于width,那么完全可以用纸宽的呢边来圈住这个圆。临界值就是width。

2.如果圆的周长大于width,那么这个圆柱的高必然是width。分割线继续向右走的话,圆的半径会一直变大,同时能够圈住这个圆的边(length-d)逐渐变小,临界点就是圆的周长正好等于length-d。

因为我们现在只在考虑圆的半径在长这条边的取值,现在我们考虑一下,在宽的这条边上圆的半径是否成立呢?

针对1, 由于2*pi*r = width 可知 r一定小于width

针对2, 由于2*pi*r = length - 2 * r 可知 r=length/(2*pi+2) 不一定小于width ,因此,我们对r取两者的最小值

#include <bits/stdc++.h>

//#define int long long
const int MAXN = 1e6 + 7;
const double pi = acos(-1);
using namespace std;
signed main() {
    double length, width;
    while(cin >> width >> length){
        if(!length || !width)break;
        double r1 = width / (2 * pi);
        double ans1 = pi * r1 * r1 * (length - 2 * r1);
        double r2 = min(length / (2 * pi + 2), width / 2);
        double ans2 = pi * r2 * r2 * width;
        printf("%.3f\n", max(ans1, ans2));
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值