Cup

Cup

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 932 Accepted Submission(s): 319
 

Problem Description

The WHU ACM Team has a big cup, with which every member drinks water. Now, we know the volume of the water in the cup, can you tell us it height?

The radius of the cup‘s top and bottom circle is known, the cup‘s height is also known.


Input

The input consists of several test cases. The first line of input contains an integer T, indicating the num of test cases.
Each test case is on a single line, and it consists of four floating point numbers: r, R, H, V, representing the bottom radius, the top radius, the height and the volume of the hot water.

Technical Specification

1. T ≤ 20.
2. 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.
3. r ≤ R.
4. r, R, H, V are separated by ONE whitespace.
5. There is NO empty line between two neighboring cases.


Output

For each test case, output the height of hot water on a single line. Please round it to six fractional digits.


Sample Input

1
100 100 100 3141562


Sample Output

99.999024

 

Source

The 4th Baidu Cup final


Recommend

lcy

/*
一晚上把底半径和二分的右区间变量名用重了,还看出来,真是.....
*/
#include<bits/stdc++.h>
#define op 1e-9
#define pi acos(-1.0)
using namespace std;
/*
V=π×h×(R2﹢R×r﹢r2)/3 
*/
double S(double r,double R,double h,double H)//圆台面积
{
    double r1=r+h*(R-r)/H;
    return pi*h*(r1*r1+r1*r+r*r)/3;
}
int main()
{
    //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
    int t;
    double left,right,h,v;
    double r,R,H,V;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
        //cout<<r<<" "<<R<<" "<<H<<" "<<(int )V<<endl;
        left=0,right=100;
        while(right-left>op)
        {
            //cout<<h<<endl;
            h=(right+left)/2;
            v=S(r,R,h,H);
            //cout<<v<<endl;
            if(fabs(v-V)<=op)
                break;
            else if(v>V)
                right=h-op;
            else
                left=h+op;
        }
        printf("%.6lf\n",h);
    }
    return 0;
}
时间: 2024-10-14 18:24:24

Cup的相关文章

HDU 2289 Cup

Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5597    Accepted Submission(s): 1787 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th

ZOJ 1584:Sunny Cup 2003 - Preliminary Round(最小生成树&amp;amp;&amp;amp;prim)

Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via networks. If two QS want to get connected, they

uva 6757 Cup of Cowards(中途相遇法,貌似)

uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 di?erent characters (Mage, Tank, Fighter,Assassin and Marksman). A team consists of 5 players (one from each kind) and the goal is to kill amonster with L life points. The

[BZOJ 3145][Feyat cup 1.5]Str 解题报告

[Feyat cup 1.5]Str DescriptionArcueid,白姬,真祖的公主.在和推倒贵看电影时突然对一个问题产生了兴趣:我们都知道真祖和死徒是有类似的地方.那么从现代科学的角度如何解释呢?自然就得研究遗传密码了.Arcueid得知了两者的DNA片段,想寻求一个DNA片段,使得其在两者的DNA中都出现过.我们知道公主的脑袋有点不太灵活,如果两个DNA片段只有一个位置不同,她也会将其认为是相同的.所以请您找出这样的最长的DNA片段吧.Input两行,每行一个字符串.Output一个

pat1011. World Cup Betting (20)

1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battl

POJ1953 World Cup Noise

这题纯暴力会超时,只需简单推一下递推公式即可,其实就是一个斐波拉契数列. World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15937   Accepted: 7861 Description Background "KO-RE-A, KO-RE-A" shout 54.000 happy football fans after their team has reached the

poj 3117 World Cup(简单数学题)

题目链接:http://poj.org/problem?id=3117 World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8634   Accepted: 4327 Description A World Cup of association football is being held with teams from around the world. The standing is based on

2014 New Air Jordans 6 World Cup Brazil For Sale

Jordan Brand has been going out of the Air Jordan 6 World Cup Brazil ordinary with some of their Retro colorways over the last few years and the trend continues. Along side the OG White/Varsity Red Retro 2s JB will be dropping few new colors with one

Poj 3117 World Cup

1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8778   Accepted: 4406 Description A World Cup of association football is being held with teams from around the world. The standin