Expanding Rods (POJ-1905)(二分+计算几何)

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

题意:给你一根长为l的长方形,然后在温度升高的时候,长方形会变成圆弧,然后圆弧的长给了你一个公式,s=(1+n*c)*l;

n是升高的温度,c是温度系数,然后问你加热之后,长方形的中心上移了多少。

思路:这道题的话是几何知识+二分查找的结合题,根据几何知识,可以画一个图。

                                            

如图所示,能得到几个公式:

1.θ*r=1/(2*s)

2.sinθ=((1/2)*l)/r

3.r*r-(r-h)*(r-h)=((1/2)*l)*((1/2)*l)

然后把这三个式子结合一下就是:

1.r=(4*h*h+l*l)/(8*h);

2.s=2*r*arcsin(l/(2*r))

然后推导一下,想算r就要算h,所以我们就在范围里查找mid的值,让它和s做比较,然后再算。

但是范围的话需要我们判断一下,题里说加热后最大弯曲不超过3/2l,然后我们很容易就能得到,在1~2/l里就可以满足。

所以范围就是1~2/l。然后这道题就大致解出来了,剩下的看看代码吧。

AC代码:

#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
typedef long long ll;
const double jingdu=1e-5;
using namespace std;
int main()
{
    double l,n,c,s,r,h;
    while(cin>>l>>n>>c)
    {
        if(l<0 && n<0 && c<0)
            break;
        s=(1+n*c)*l;
        double low=0.0;
        double high=0.5*l;
        double mid;
        while(high-low>jingdu)
        {
            mid=(high+low)/2;
            r=(4*mid*mid+l*l)/(8*mid);
            if(2*r*asin(l/(2*r))<s)
                low=mid;
            else
                high=mid;
        }
        h=mid;
        printf("%.3lf\n",h);
    }
    return 0;
}
发布了204 篇原创文章 · 获赞 16 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43846139/article/details/103641964