<<  < 2013 - >  >>
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31




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. 


原题如上


最开始我看题想打的办法是直接计算,因为从前也学习过工程力学嘛,知道这个可以计算的。

但是深入一想发现过去的计算都只是近似的计算,但是这次的计算要求十分的精确。

无奈只好放弃了直接计算的方法。

看了一下别人的题解,才发现原来是是二分总共的范围。知道达到精度就ok了。

其实真的很简单,这是以前没有做过类似的题目。

还有一点 <cmath> 中有asin函数,是数学之中的arcsin这个题目必须用到啊。

题号为POJ1905,下面贴个代码吧。。。

#i nclude <iostream>
#i nclude <cstdio>
#i nclude <cstring>
#i nclude <cmath>
#define exp 1e-6
using namespace std;

double l,n,c;

int main()
{
    double h,s,r,l1,bot,top;
    while (scanf("%lf%lf%lf",&l,&n,&c) && l>=0)
    {
        l1=(1+n*c)*l;
        top=l/2;
        bot=0;
        while (top-bot>=exp)
        {
            h=(top+bot)/2;
            r=(l*l+h*h*4)/(8*h);
            s=2*r*asin(l/(2*r));
            if (s<=l1) bot=h;
                else top=h;
        }
        printf("%.3lf\n",bot);
    }
    return 0;
}



发表评论:
天涯博客欢迎您!