鱼C论坛

 找回密码
 立即注册
查看: 2988|回复: 2

[技术交流] 048:UmBasketella(三分)

[复制链接]
发表于 2018-2-18 21:41:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Description

In recent days, people always design new things with multifunction. For instance, you can not only use cell phone to call your friends, but you can also use your cell phone take photographs or listen to MP3. Another example is the combination between watch and television. These kinds of multifunction items can always improve people's daily life and are extremely favored by users.

The company Mr. Umbrella invented a new kind umbrella "UmBasketella" for people in Rainbow city recently and its idea also comes from such multifunction--the combination of umbrella and daily necessities. This kind of umbrella can be used as a basket and you can put something you want to carry in it. Since Rainbow city rains very often, such innovative usage is successful and "UmBasketella" sells very well. Unfortunately, the original "UmBasketella" do not have an automatic volume control technology so that it is easily damaged when users try to put too many things in it. To solve this problem, you are needed to design an "UmBasketella" with maximum volume. Suppose that "UmBasketella" is a cone-shape container and its surface area (include the bottom) is known, could you find the maximum value of the cone?

Input

Input contains several test cases. Eash case contains only one real number S, representing the surface area of the cone. It is guaranteed that 1≤S≤10000.

Output

For each test case, output should contain three lines.
The first line should have a real number representing the maximum volume of the cone.
Output the height of the cone on the second line and the radius of the bottom area of the cone on the third line.
All real numbers should rounded to 0.01.

Sample Input

30
Sample Output

10.93
4.37
1.55

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-2-18 21:59:58 | 显示全部楼层
题目描述

给定圆锥的表面积S,求这个圆锥的最大体积V,以及此时它的高h与底面半径r。

输入

输入数据中有多个测试点,每个测试点只包含一个实数 S, 代表圆锥的表面积。表面积 1≤S≤10000.

输出

对于每个测试点,输出应该包含三行:
第一行输出最大体积V;
第二行输出高h;
第三行输出底面半径r;
所有实数应该四舍五入到0.01。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-2-18 22:05:59 | 显示全部楼层
NaN,是Not a Number的缩写。   
NaN 用于处理计算中出现的错误情况,比如 0.0 除以 0.0 或者求负数的平方根。由上面的表中可以看出,对于单精度浮点数,NaN 表示为指数为 emax + 1 = 128(指数域全为 1),且尾数域不等于零的浮点数。IEEE 标准没有要求具体的尾数域,所以 NaN 实际上不是一个,而是一族。不同的实现可以自由选择尾 数域的值来表达 NaN,比如 Java 中的常量 Float.NaN 的浮点数可能表达为01111111110000000000000000000000,其中尾数域的第一位为 1,其余均为 0(不计隐藏的一位),但这取决系统的硬件架构。

本题中由于左右边界设置过大,导致计算出R<r,故sqrt(负值)为nan。

#include<cstdio>
#include<cmath>
#include<algorithm>
#define eps 10e-6
#define pi acos(-1.0)

using namespace std;

double S;
double cal(double r)
{
        double R=S/pi/r-r;
        double h=sqrt(R*R-r*r);
        return h*pi*r*r/3;
}
int main()
{
        while(scanf("%lf",&S)!=EOF)
        {
                double l=0,r=sqrt(S/pi);
                double mid,mmid;
                while(l+eps<r)
                {
                        mid=l+(r-l)/3;
            mmid=r-(r-l)/3;
                        /*
                        mid=(l+r)/2.0;
                        mmid=(mid+r)/2.0;//不存在以该底半径且表面积为S的圆锥 
                        */
                        if(cal(mid)>cal(mmid))
                                r=mmid;
                        else
                                l=mid;
                }
                double R=S/pi/r-r;
                double h=sqrt(R*R-r*r);
                double V=h*pi*r*r/3;
                printf("%.2f\n%.2f\n%.2f\n",V,h,r);
        }
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-6 07:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表