标题:学校里没一个人会的问题,速求解答!!
只看楼主
zz199200
Rank: 1
等 级:新手上路
帖 子:18
专家分:2
注 册:2011-11-26
结帖率:75%
已结贴  问题点数:20 回复次数:15 
学校里没一个人会的问题,速求解答!!
Problem Description
Zero recently bought a new bottle which is a circular truncated cone. He likes this bottle very much as this bottle is limited version. One day he wonder how high the water is after pouring some water into the bottle. Can you tell him the height of the water?

You are given the radius of the bottle's top and bottom circle. The bottle's height is also given.
Input
The first line contains an integer T which means the number of test cases.

Each test case contains four float point number: r, R, H, V(1<= r, R, H<=100; r<=R; 0<=V<=1000000000) within one line. ‘r’ indicates the bottom radius. ‘R’ indicates the top radius. ‘H’ indicates the height. ‘V’ indicates the volume of the water.
Output
For each case, just output one line containing one float point number which describes the height of the water. Note that you should round the number to six fractional digits.
Sample Input
1
100 100 100 3141562
Sample Output
99.999024
搜索更多相关主题的帖子: him 学校 recently version limited 
2011-12-02 19:25
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:7 
你们学校的水平很次啊,只是一个简单的物理题而已。

重剑无锋,大巧不工
2011-12-02 19:31
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
得分:7 
程序代码:
#include <stdio.h>
#define    PI    3.141592653

int main ()
{
    double    r, R, H, V;
    int        t;
   

    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%lf%lf%lf%lf", &r, &R, &H, &V);
        if (V / PI / (R * R + R * r + r * r) * 3 > H)
        {
            printf ("%.6lf", H);
        }
        else
            printf ("%.6lf\n", V / PI / (R * R + R * r + r * r) *3);
    }

    return 0;
}
没什么技术含量,单纯的圆台公式而已。


冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2011-12-02 21:00
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:0 
小樊没仔细看题。比这要复杂一点,需要用迭代法求取近似值。

重剑无锋,大巧不工
2011-12-02 21:16
wang155423
Rank: 6Rank: 6
等 级:侠之大者
帖 子:216
专家分:408
注 册:2011-9-4
得分:7 
回复 3楼 waterstar
圆台体积公式有误
2011-12-02 23:50
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
得分:0 
杨大哥,我是小蔡……

冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2011-12-03 16:33
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
得分:0 
回复 5楼 wang155423
这题出处在哪?

冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2011-12-03 16:35
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:0 
回复 6楼 waterstar
哦,非常抱歉,怎么会记错了呢,对不住啊

重剑无锋,大巧不工
2011-12-03 17:36
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:0 
回复 7楼 waterstar
杭电2289就是这题。这题有多种做法,我的方法很传统,先求体积与高度的函数(没记过圆台的体积公式,直接解了一个积分函数),然后用牛顿法迭代求出高度。

重剑无锋,大巧不工
2011-12-03 18:53
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
得分:0 
程序代码:
#include <stdio.h>
#include <math.h>

int main ()
{
    double    r, R, H, V;
    int        t;
    const    double PI = acos (-1.0);
    double    high, low, rmid, vmid, mid;
   

    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%lf%lf%lf%lf", &r, &R, &H, &V);
        low = 0;
        high = H;
        for (; high - low > 0.000000001;)
        {
            mid = (high + low) / 2;
            rmid = mid / H * (R - r) + r;
            vmid = PI * (rmid * rmid + r * rmid + r * r) * mid / 3;
            if (vmid > V)
                high = mid;
            else
                low = mid;
        }
        printf ("%.6lf\n", mid);
//        if (V / PI / (R * R + R * r + r * r) * 3 > H)
//        {
//            printf ("%.6lf", H);
//        }
//        else
//            printf ("%.6lf\n", V / PI / (R * R + R * r + r * r) *3);
    }

    return 0;
}

明明有现成的圆台公式不用,非要去逼近求值,可气。

冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2011-12-03 20:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-356802-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.090086 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved