POJ 1905Expanding Rods(计算二分)

来源:互联网 发布:温州网络学堂手机版 编辑:程序博客网 时间:2024/04/28 19:09

Expanding Rods

Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 15693 Accepted: 4165

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.000115000 10 0.0000610 0 0.001-1 -1 -1

Sample Output

61.329225.0200.000

Source

题意:一种材料加热会发生伸长,放在两个固定的物体中间会发生弯曲,求弯曲的高度,给定原长l,材料的系数n和温度,伸长的公式是l' = (1 + n * c)* l, 求高度h。

题解:首先用数学的方式来分析一下,讲变形后的材料当做弧形,弧形的半径是r,则弧形的弧长l' = 2 * r * asin(l /(2 * r))----公式1,根据勾股定理和三角形相似作比求出这么一个式子h/(根号下(h^2+(1/4)l^2)/ 2)=  根号下(h^2 + (1/4)l^2)/r,整理得r = (4 * h^2 + l^2)/(8*h)----公式2

所以由公式2求出公式1,从0~l的范围内二分找h, 也可以将公式2带人公式1求,不过就非常麻烦了。


二分代码

#include <iostream>#include <stdio.h>#include <math.h>using namespace std;int main(){    double l, n, c;    while(~scanf("%lf%lf%lf", &l, &n, &c))    {        if(l < 0 && c < 0 && n < 0)            break;        double L = (1 + n * c) * l;        double high = l;        double low = 0.0;        double mid;        while(high > low + 0.00001)        {            mid = (high + low) / 2;            double r = (4*mid*mid + l*l) / (8*mid);            if(2*r*asin(l/(2*r))< L)                low = mid;            else                high = mid;        }        printf("%.3f\n", mid);    }    return 0;}

0 0
原创粉丝点击