2014
02-09

# Timer

Recently, some archaeologists discovered an ancient relic on a small island in the Pacific Ocean. In the relic, they found an interesting cone shaped container with transparent bottom. The container lay on the horizontal ground with its central axis parallel to the ground. Just beside the container, they found a manual telling them something about the container.

The container was a timer for a special ceremony. Ancient people filled it all with water before the ceremony, and when the ceremony began, they pulled out the plug in the small hole on the tip of the cone to let the water out. There was a horizontal line called “sacred line” carved on the bottom of the cone, and when the water level hit that line, they pushed the plug back and ended the ceremony. But the archaeologists could not found the sacred line on that cone. In order to sell the timer at a good prize, the archaeologists wanted to recover that very important line.

By the manual they figured out how much water flew out when the ceremony ended, but they don’t know what to do next, so they come to you for help.

They measures the height of the cone, and the diameter of the bottom, you should tell them the sacred line’s height above the ground.

The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases.

Each line after that is a test case. It contains three real numbers, H, D(1<=H,D<=1000) and V, indicating the height and bottom diameter of the timer, and the volume of water that flew out during the ceremony. That volume is guaranteed to be less than half volume of the container.

The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases.

Each line after that is a test case. It contains three real numbers, H, D(1<=H,D<=1000) and V, indicating the height and bottom diameter of the timer, and the volume of water that flew out during the ceremony. That volume is guaranteed to be less than half volume of the container.

2
5.0 10.0 0.0
5.0 10.0 65.4498

10.00000
5.00000



AC代码：

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s)  scanf("%s",s)
#define pi1(a)    printf("%d\n",a)
#define pi2(a,b)  printf("%d %d\n",a,b)
#define mset(a,b)   memset(a,b,sizeof(a))
#define forb(i,a,b)   for(int i=a;i<b;i++)
#define ford(i,a,b)   for(int i=a;i<=b;i++)

typedef long long LL;
const int N=100005;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;

double H,D,V,R;

double xiaohao(double r)//这个地方求积分很麻烦，我就只写结果了
{
double xh=0;
xh+=H*R*R*acos((R-r)/R)/3.0;
xh-=2.0/3.0*(R-r)*H*sqrt(R*R-(R-r)*(R-r));
xh+=1.0/3.0*(R-r)*(R-r)*(R-r)*H/R*log((R+sqrt(R*R-(R-r)*(R-r)))/(R-r));
return xh;
}

int main()
{
//    freopen("input.txt","r",stdin);
int i,j,T;
si1(T);
while(T--)
{
sd1(H);sd2(D,V);
R=D/2;
double low=0,up=R,m,tmp;
while((up-low)>eps)//二分高度
{
m=(up+low)/2;
double tmp=xiaohao(m);//求出体积，和V比较
if(tmp>V)
up=m;
else
low=m;
}
printf("%.5f\n",D-m);
}
return 0;
}