FZUOJ Problem-1010 Beavergnaw (数学公式水题)

FZUOJ Problem-1010 Beavergnaw

Accept: 839 Submit: 1444 Time Limit: 1000 mSec Memory Limit : 32768 KB

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.
FZUOJ Problem-1010 Beavergnaw (数学公式水题)_第1张图片
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?

Inputcontains 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+圆柱d)求出来相加公式化简v = 1/6 (D^3-d^3)*pi 开根号就好;
还有个思路:找到以D为直径的大菠萝 ( VD - 2VD’ ) 减掉以d为直径的小菠萝( Vd - 2Vd’ ) ,就是鼠吃的木头体积。VD’ Vd’ 是分别以D和d为直径的圆锥。
简化 v = 1/6 (D^3-d^3)*pi
d^3 = D^3-6*v/pi
WA 是因为0.333333缺了精度 ~ 看网上的是1.00/3
ps: FZUOJ 就是恶心,上代码

#include"iostream"
#include"cstdio"
#include"cmath"
using namespace std;
double pi =  acos(-1);
int main(){
    double D,v,res;
    while(~scanf("%lf %lf",&D,&v)&&(D||v)){    
        res = D*D*D-6*v/pi;
        printf("%.3lf\n",pow(res,0.3333333333333));
    }
    return 0;
}

你可能感兴趣的:(水,FZU)