标签:empty hot put main between HERE amp break contains
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.
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
For each test case, output the height of hot water on a single line. Please round it to six fractional digits.
1
100 100 100 3141562
99.999024
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
#define for(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e12+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
db V,r,R,H;
int judge(db mid)
{
db rr=(R-r)*mid/H+r;
db v=(1/3.0)*pi*mid*(rr*rr+r*r+rr*r);
if(v==V) return 0;
if(v>V) return 1;
return -1;
}
int main()
{
int re;
cin>>re;
while(re--)
{
sf("%lf%lf%lf%lf",&r,&R,&H,&V);
db right=H,left=0,mid;
while(right-left>0.00000001)
{
mid=(left+right)/2;
if(judge(mid)==0)
break;
else if(judge(mid)>0)
right=mid;
else
left=mid;
}
pf("%.6lf\n",mid);
}
return 0;
}
标签:empty hot put main between HERE amp break contains
原文地址:https://www.cnblogs.com/wzl19981116/p/9382381.html