题意:
给你两个相交的梯子。现已知道它们的长度以及相交点距离地面的高度c,现在让你求出梯脚间的距离。
思路:
二分梯脚间的距离即可。运用几何知识求出相交点的距地的高度进行比较。
AC代码:
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
double x, y, c;
bool OK(double mid)
{
double k1 = tan(acos(mid/y));
double k2 = - tan(acos(mid/x));
double tmp = k2/k1 - 1;
double ty = k2*mid/tmp;
if(ty <= c) return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
int T, cas = 0;
cin>>T;
while(T--)
{
cin>>x>>y>>c;
double l = 0, r = min(x, y);
while(r - l > 1e-8)
{
double mid = (l+r)/2;
if(OK(mid))
l = mid;
else
r = mid;
}
cout<<"Case "<<++cas<<": "<<fixed<<setprecision(6)<<l<<endl;
}
return 0;
}