G - Expanding Rods poj 1925

问题描述

G - Expanding Rods poj 1925_第1张图片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.

样例输入

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1

样例输出

61.329
225.020
0.000


做一个扇形区域出来,经过数学分析,不难发现半径r满足:

 r=(D+d*d/4)/(2*D);
其中D为所求值,d为原长,l加热后的弧长,r为半径;其满足
<pre name="code" class="cpp">arcsin(d/(2*r))*2*r=l   这个超越方程
因此用二分法求解,需要注意的是本题对精度有要求

 
 

但对精度有要求



#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

double esp=1e-6;//精度

int main()
{
    double d,l,c,n,r;
    while(scanf("%lf%lf%lf",&d,&n,&c))
    {
        l=(1+n*c)*d;
        if(d==-1&&n==-1&&c==-1)
            break;

        double ll=0.0;//0是h的下界
        double rr=d*0.5;//0.5不一定是他的上确界,但一定是上界;
        double mid=0;
        while(rr-ll>esp)
        {
             mid=(ll+rr)/2;
            r=(mid*mid+d*d/4)/(2*mid);
            if(asin(d/(2*r))*2*r>l)
                rr=mid;
            else
                ll=mid;

        }
        printf("%.3f\n",mid);//输出可以用cout;但一定不可以用printf("%.3lf\n",mid);
    }
}


你可能感兴趣的:(G - Expanding Rods poj 1925)