【三分】Expanding Rods

Expanding Rods
Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u
Submit  Status

Description

When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. 
When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment. 

Your task is to compute the distance by which the center of the rod is displaced. 

Input

The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.

Output

For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision. 

Sample Input

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1

Sample Output

61.329
225.020
0.000
 
    
 
    
 
    
题目意思是 已经知道图中的弧线和直线的长度 ,求弧线中心和直线中心的距离。
可以推出公式 。然后用三分法,本题目并不是完全的单调函数 ,不应该用二分法。
坑点多 卡精度 e-12 ,然后n,l,c任意一个为0时应该输出0
 
    
 
    
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
//double eps=1e-12;

double l,n,c;
  double ll;

bool ok(double x)
{

    if(sin(x)-l*x/ll>=0)
        return 1;
    else
        return 0;

}
int main()
{

    while(scanf("%lf%lf%lf",&l,&n,&c)!=EOF)
    {
        if(l<0&&n<0&&c<0)
            break;

            if(l==0||n==0||c==0)
            {
                puts("0.000");
                continue;
            }
       ll=(1+n*c)*l;
       double le=0;
       double ri=90;
       while(ri-le>1e-12)
       {
           double mid=(le+ri)/2;
            double mm=(mid+ri)/2;
           if(ok(mid))
           {
               le=mid;
           }
           else
            {
              //  ri=mid;
               ri=mm;
            }

       }


        printf("%.3f\n",ll/2/ri*(1-cos(ri)));
    }


    return 0;
}

你可能感兴趣的:(【三分】Expanding Rods)