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;
}

 

全部评论

相关推荐

11-28 17:48
中山大学 C++
点赞 评论 收藏
分享
10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务