最省納智捷1年新車83萬起新手>新婚族選績優龍頭股 攝影界美人正妹指定相機款反服貿流血 法官要警交...
2013-05-14 09:52:06 人氣(196) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][二分] 10668 - Expanding Rods

0
收藏
0
推薦

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;
}

10668Expanding Rods
台長:Morris
人氣(196) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][二分] 11646 - Athletics Track
此分類上一篇:[UVA][困難dp] 1238 - Free Parentheses

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文