holiday/8.21/B-Light/main.cpp

36 lines
527 B
C++
Raw Normal View History

2022-08-22 22:19:52 +08:00
#include <iostream>
#include<cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
2022-08-22 23:17:19 +08:00
const double eps= 1e-5;
double H,h,D;
double f(double d)
{
return D-d+H-(H-h)*D/d;
// return D-d+h-(H-h)*(D-d)/d;
}
double sanfen(double l,double r)
{
double mid,midr,ans;
while(fabs(r-l)>eps)
{
mid=(l+r)/2;
midr=(mid+r)/2;
if(f(mid)<f(midr))l=mid;
else r=midr;
}
return f(l);
}
2022-08-22 22:19:52 +08:00
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&H,&h,&D);
2022-08-22 23:17:19 +08:00
printf("%.3lf\n",sanfen(D-D*h/H,D));
2022-08-22 22:19:52 +08:00
}
return 0;
}