POJ 1905 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. 
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

题意:有一根木棒,固定在两面墙之间,它会受热弯曲,弯曲只会让它变长,可是由于两面墙是固定的,所以它变长会导致它弯曲,它的弯曲也有特点,它会以圆弧的形式向上弯曲(注意是个圆弧!),木棒弯曲的程度受温度和热膨胀系数影响,题目有多组输入,每组输入给出三个数,分别是,木棒的初始长度:Length,温度:Temperature,系数:Coefficient,最后输出弯曲后的木棒的最上方(即圆弧顶点),距离原始木棒有多远的距离。




#include <math.h>
#include <stdio.h>
#include <string.h>
#define f_1(h) (Inp.Length*Inp.Length+4*h*h)/(8*h)//求半径R
#define f_2(R) 2*R*asin(Inp.Length/(2*R))         //求预计弧长
#define f_3() (1+Inp.Temperature*Inp.Coefficient)*Inp.Length//求真实弧长
struct num{
    double Length;     //长度
    double Temperature;//系数
    double Coefficient;//热弯曲率
    double num1(){     //三者求和,判断条件,-1停止
        return Length + Coefficient + Temperature;
    }
}Inp;

int cal(double h) {     //计算
    double R = f_1(h);
    double L1 = f_2(R);//二分得到的弧长
    double L2 = f_3(); //题目给出的弧长
    if(L1 > L2) return 1;//如果预计弧长大于真实弧长
    else return 0;
}

int main() {
    while(~scanf("%lf%lf%lf",&Inp.Length,&Inp.Coefficient,&Inp.Temperature)) {
        if(Inp.num1() == -3) break;
        double left = 0, right = Inp.Length/2, mid;
        int temp = 0; //避免陷入死循环
        while(right - left > 1e-9) {
            temp++;
            mid = (left + right)/2;
            if(cal(mid)) {
                right = mid;
            }
            else left = mid;
            if(temp > 50) break;   //停止循环
        }
        printf("%.3f\n", left);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值