UVALive7198 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.

A cable hanging between poles is known to assume a specific shape called a catenary. This shape is described by the formula

where  denotes a position along the cable, as measured on the ground, and

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

 

题目大意:火车铁轨两侧分别有一个电线杆,他们之间的距离为d,高度相同,均为p。在两个电线杆顶挂电缆,电缆自然下垂,两个电线杆之间的电缆曲线满足f(s),x=0所在的位置为两个电线杆的正中间。求电缆最低处大于等于4.2米时电缆的最长长度。

题解:

讲道理这些题为什么这么多英文……看的脑袋疼……这道题题意简直是连猜带蒙……

就是对悬链线的线积分,已知悬链线方程F(s)=f(s)+b,b未知,f(s)里面也有一个未知的常量a。所以需要先求出a,再对f(s)求线积分。因为-d/2<=s<=d/2,所以f(d/2)-f(0)=p-4.2,即

用二分求出a的值,然后把a值带入f(s),求线积分。线积分公式:

最后求出来的线积分是:

这题还有一个需要注意的点,就是最后输出的结果保留三位小数,但不是四舍五入,而是把后面的小数全部舍弃。(因为这个WA了好多次……根本不认识这个单词orz)这里我是利用的强制类型转换。

#include <iostream>
#include <cmath>
#include <math.h>
#include <cstdio>

using namespace std;

double p, d;

int judge(double a)
{
    double b, c;
    b=a*1.0*(exp(d*1.0/(2*a))+exp(-d*1.0/(2*a))-2);
    c=2*(p-4.2);
    if(b-c>0.0000001) return 1;
    else if(c-b>0.0000001) return -1;
    else return 0;
}

int main()
{
    double ans;
    while(scanf("%lf", &p) && p!=-1)
    {
        scanf("%lf", &d);
        double left, right;
        double mid;
        left=0.0, right=100000.0;
        while(left<right)
        {
            mid=(left+right)*1.0/2;
            int x=judge(mid);
            if(x==1)
            {
                left=mid;
            }
            else if(x==-1)
            {
                right=mid;
            }
            else break;
        }
        ans=mid*(exp(d*1.0/(2*mid))-exp(-d*1.0/(2*mid)));
        ans=(int)(ans*1000);
        ans=(double)(ans*1.0/1000);
        printf("%.3lf\n", ans);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值