2013-05-14 09:52:06Morris

[UVA][二分] 10668 - Expanding Rods

Problem A: Expanding Rods

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.

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.

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

Output for sample input

61.329
225.020
0.000

P. Chrzastowski-Wachtel, adapted by P. Rudnicki

題目依序給 L, C, n,藉此算出 L',然後二分半徑 R,看能不能接近 L',

找到 R 之後,計算張角後計算即可。
//彎曲的部分是圓的一小部分。


#include <stdio.h>
#include <math.h>

int main() {
    double  L, C, n;
    const double pi = acos(-1);
    while(scanf("%lf %lf %lf", &L, &C, &n) == 3) {
        if(n < 0)
            break;
        double LL = (1 + n*C)*L;
        double l = 0, r = pi/2, theta, R;
        int cnt = 0;
        while(l <= r && cnt < 50) {
            theta = (l+r)/2;
            R = L/2/sin(theta);
            if(R*2*theta < LL)
                l = theta;
            else
                r = theta;
            cnt++;
        }
        printf("%.3lf\n", R-R*cos(theta));
    }
    return 0;
}