poj 1905 Expanding Rods

http://poj.org/problem?id=1905

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const double K=1e-10;
const double PI=acos(-1);
int main()
{
    double L,n,C;
    while(cin>>L>>n>>C)
    {
        if(L<0&&n<0&&C<0)
        break;
        double L1=(1+n*C)*L;
        double high=PI;
        double low=0;
        double mid=(high+low)/2;
        while(high-low>K)
        {
            //cout<<(mid/2)<<" "<<sin(mid/2)<<endl;
            //cout<<L1<<" "<<(mid*(L/2*asin(mid/2)))<<endl;
            if(L1-(mid*(L/2/sin(mid/2)))>=K)
            {
                low=mid;
            }
            else
            {
                high=mid;
            }
            mid=(high+low)/2;
        }
        //cout<<mid<<endl;
       printf("%.3f\n",(L/2/sin(mid/2)-L/2/tan(mid/2)));
    }
    return 0;
}

你可能感兴趣的:(exp)