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
Hint

You can use π=3.14159265 and eps=1e-8.

题意:一根长度为L的细杆在加热n度之后会伸展成L‘=(1+n*C)*L,C是热膨胀系数。当细杆放在两堵墙中间时,由于加热后的伸展效果会使细杆弯曲成圆弧状,而原来的细杆就会变成这段弧的弦。问前后两个状态下细杆的中点的位移是多少,保留三位小数。题中说输入三个负数结束,并不只是输入三个-1结束。

我们设位移是h,圆的半径是r,从题中得到三条关系式;

(1)       设圆心角是2θ,θr = L’/2

(2)       三角函数公式  sinθ= L/(2*r)

(3)       勾股定理  r^2 – (r – h)^2 = (L/2)^2

 关系式化简可以得到s=L‘

 

要求(1)式的h,唯有先求r,但是由于(2)式是三角函数式,直接求r比较困难

因此要换种思维解方程组:

在h的值的范围内枚举h的值,计算出对应的r,将这个r带入(2)式判断左右两边是否相等


 所以我们使用二分查找

下面我们来确定 h 的范围是多少:下界自然是0 (不弯曲时两个状态是重合的,位移是0);关键确定上界,题中提及到Input data guarantee that no rod expands by more than one half of its original length. 即输入的数据要保证没有一条杆能够延伸超过其初始长度的一半

就是说 S max = 3/2 *L。理论上把3/2*L代入(1)就能求到h的最小上界,但是实际操作很困难。因此这里可以做一个范围扩展,把h的上界扩展到 1/2L  ,这个值必定大于h的最小上界,那么h的范围就为  0<=h<1/2L

这样每次利用下界low和上界high就能得到中间值mid,寻找最优的mid使得(2)式左右两边差值在精度范围之内,那么这个mid就是h

 此题肯定要考虑精度1e-8。



#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
    double L,n,C,S,r;
    while(cin>>L>>n>>C)
    {
        if(L<0&&n<0&&C<0)
            break;
        double low=0,high=0.5*L,mid;
        S=(1+n*C)*L;
        while(high-low>=1e-8)
        {
            mid=(low+high)/2;
            r=(4*mid*mid+L*L)/(8*mid);
            if(2*r*asin(L/(2*r))<S)
                low=mid;
            else
                high=mid;
        }
        cout<<setiosflags(ios::fixed)<<setprecision(3);
        cout<<mid<<endl;
    }
    return 0;
}

posted on 2014-09-26 20:28  星斗万千  阅读(108)  评论(0编辑  收藏  举报