我是靠谱客的博主 唠叨薯片,最近开发中收集的这篇文章主要介绍1001: 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

#include <stdio.h>
#define PI 3.141592653589793238
int main()
{
    double w, h, r, result1, result2;
    while(scanf("%lf%lf", &w, &h) == 2 && w != 0)
    {
        r = w / (2 * PI);
        result1 = PI * r * r * (h - 2 * r);
        r = h / (2 * PI + 2);
        r = r * 2 > w ? w / 2 : r;
        result2 = PI * r * r * w;
        printf("%.3fn", result1>result2 ? result1:result2);
    }
    return 0;
}

最后

以上就是唠叨薯片为你收集整理的1001: Cylinder的全部内容,希望文章能够帮你解决1001: Cylinder所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部