UVALive - 7198 Tall orders (构造函数等式二分求参数)

You have been charged with evaluating the safety of power cables passing over train tracks. Owing to the recent purchase of the new Macho 10000 trains, the questions has been raised as to whether the trains are too tall to safely pass under existing power cable infrastructure. The new Macho 10000 train is 4.1 m tall; the power engineers claim that the power lines have been designed for a maximum train height of 4.05 m, with a safety gap of 150 mm for thermal expansion in the cables. Fortunately the data required to test this claim is available: you have a complete database of the critical dimensions of all power line infrastructure passing over train tracks. In particular, you have the following dimensions (see Figure 1): • The distance between the two posts supporting the power cable, d. You may safely assume that the train track is exactly halfway between the two posts. • The height of the top of the posts above the track, p. You may safely assume that the cable is attached right at the top of the post. Figure 1: Power line dimensions A cable hanging between poles is known to assume a specific shape called a catenary. This shape is described by the formula f(s) = a cosh ( s a ) where −d 2 ≤ s ≤ d 2 denotes a position along the cable, as measured on the ground, and cosh(x) = e x + e −x 2 A given configuration (specific d and p values) can be said to be safe if the lowest point along the cable is at a height of 4.2 m above the track. By modeling the cable as an infinitely thin thread, the function f(s) can be used to determine the maximum length of cable that will be safe. Input Your input consists of an arbitrary number of records, but no more than 100. Each record comprises two real numbers, p d where 4.3 ≤ p ≤ 10 denotes the height of the top of the posts above the tracks (in metres), and 6 ≤ d ≤ 30 denotes the distance between the two posts, also given in metres (see Figure 1). The end of input is indicated by a line containing only the value ‘-1’. Output For each input record, output L where L denotes the maximum length of cable that may be used while keeping the lowest point along the cable 4.2 m or more above the tracks. The value L should be given in metres, and should be truncated (not rounded) to three places after the decimal point. Sample Input 6 12 6.210381 10.184095 -1 Sample Output 12.692 11.175

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double Find_a(double p,double d)  //这个是单调减函数,和单调增函数有所区别
{
    double low=0;
    double high=1e10;
    double mid;
    while(low+1e-7<high)
    {
        mid=(low+high)/2;                            //构造函数等式二分求参数
        if(mid*cosh(d/(2*mid))-mid*cosh(0)>=p-4.2)   //利用函数差值求a,
        low=mid;                                     //a可以取到很大,只要满足这个函数关系就行
        else
        high=mid;
    }
    return high;
}
int main()
{
    double p,d;
    double a;
    while(1)
    {
        scanf("%lf",&p);
        if(p==-1)
        break;
        scanf("%lf",&d);
        a=Find_a(p,d);
        printf("%f",a);
        double len=2*a*sinh(d/(2*a));            //由曲线积分得来
        len = (int)(len * 1000) / 1000.0;        //not rounded,不四舍五入的意思
        printf("%.3f\n",len);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xigongdali/article/details/81915824