Cup

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
#include <iostream>
#include   <cstring>
#include   <cstdlib>
#include    <cctype>
#include    <cstdio>
#include    <string>
using namespace std;
double r,R,H,V;
const double Pi = 3.1415926535898;
int t;
bool sloved(double mid){
    double rt=mid/H*(R-r)+r;
    double v=1.0/3*Pi*mid*(r*r+rt*rt+r*rt);
    if(v>V)return 0;
        return 1;
}
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
        double l=0;
        double r=H;
        double mid;
        double ans=0;
        while (l<=r){
            mid=(l+r)/2;
            if(sloved(mid)){
                ans=mid;
                l=mid+0.0000001;
            }else{
                r=mid-0.0000001;
            }
        }
        printf("%.6lf\n",ans);
    }
    //cout << "Hello world!" << endl;
    return 0;
}

 

全部评论

相关推荐

03-12 16:48
已编辑
门头沟学院 C++
不想加班的L:我第一次字节审批了一周,不过是有新的hr对接的,你这个看起来像是原来招聘的hr。第二次就一天审批就完了,比较快 可以参考一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务