POJ Expanding Rods

点击打开题目

题目大意

POJ Expanding Rods

给定L,n,C,L为红色线段,L(1+n*C)为绿色弧,求两者中点的距离

二分圆心角度数,接下来就是几何的能力了

根据正弦定理,可得:

Lsinθ=rsin(90°−θ)

则弧长:

a=πr⋅θ180

将a与nL作比较来二分

精度满天飞 QWQ

代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
double pi=3.1415926535897932384626433832795,eps=0.000000001;
double L,C,n,nL;
using namespace std;
double work(double mid)
{
double a1=sin(2*pi*mid/360),a2=sin(2*pi*(90-mid/2)/360);
double r=L/a1*a2;
return 2*r*pi*mid/360;
}
int main()
{
while(scanf("%lf%lf%lf",&L,&n,&C))
{
if(L==-1&&n==-1&&C==-1)return 0;
nL=(1+n*C)*L;
if(nL==L){printf("0.000\n");continue;}
double l=0,r=180,mid;
while(r-l>eps)
{
mid=(l+r)/2;
if(work(mid)<nL)l=mid;
else r=mid;
}
printf("%.3lf\n",L/sin(2*pi*l/360)*sin(2*pi*(90-mid/2)/360)-sqrt(pow(L/sin(2*pi*l/360)*sin(2*pi*(90-mid/2)/360),2)-pow(L/2,2)));
}
}
上一篇:Python 3 入门,看这篇就够了


下一篇:两道二分coming~