fzuProblem 1010 Beavergnaw

Problem Description

When chomping a tree the beaver cuts a very specific shape out of the tree trunk. What is left in the tree trunk looks like two frustums of a cone joined by a cylinder with the diameter the same as its height. A very curious beaver tries not to demolish a tree but rather sort out what should be the diameter of the cylinder joining the frustums such that he chomped out certain amount of wood. You are to help him to do the calculations.

We will consider an idealized beaver chomping an idealized tree. Let us assume that the tree trunk is a cylinder of diameter D and that the beaver chomps on a segment of the trunk also of height D. What should be the diameter d of the inner cylinder such that the beaver chmped out V cubic units of wood?

Input contains multiple cases each presented on a separate line. Each line contains two integer numbers D and V separated by whitespace. D is the linear units and V is in cubic units. V will not exceed the maximum volume of wood that the beaver can chomp. A line with D=0 and V=0 follows the last case.

For each case, one line of output should be produced containing one number rounded to three fractional digits giving the value of d measured in linear units.
Sample Input
10 250
20 2500
25 7000
50 50000
0 0
Sample Output
8.054
14.775
13.115
30.901
分析:其实常规方法就可以解的,但是我没有化简,以为不能直接解的,然后直接用2分求,后面有发现方程不是线性的,用2分法做结果不正确。看了解题报告,顿时感觉……。

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
double pi=acos(-1);
int main()
{
    double d,v;
    while(scanf("%lf %lf",&d,&v),(d+v))
    {
        double ans=pow(d,3)-6*v/pi;
        printf("%.3lf\n",pow(ans,1.0/3));
     } 
     return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值