一道精度很高的问题,虽然也不是很难
传送门:二分查找答案
题解:
求出
r=(L^2+4h^2)/8h
s=(2r*arcsin(L/2r))
二分区间查找h
和真正的s
对比当l-r>exp
不满足时候跳出求解答案
注意:
因为精度很高所以这里的折半不应该用/2.0
而是*0.5
,*0.5
的精度更高
AC代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define exp 1e-8
using namespace std;
double L,C,k;
double GetS(double h)
{
double r=(pow(L,2)+4*pow(h,2))/(8*h);
double s=2*r*asin(L/(2*r));
return s;
}
int main()
{
while(~scanf("%lf %lf %lf",&L,&C,&k))
{
if(L<0&&C<0&&k<0)
break;
if(L==0||C==0||k==0)
{
printf("0.000\n");
continue;
}
double Lx=(1.0+k*C)*L;
double l=0,r=L*0.5,ans;
while(r-l>exp)
{
double mid=(l+r)*0.5;
if(GetS(mid)>Lx)
{
r=mid-1e-9;
ans=mid;
}
else
{
l=mid+1e-9;
}
}
printf("%.3lf\n",ans);
}
}