# 【二分】【自适应Simpson】Bridge

515人阅读 评论(0)

A suspension bridge suspends the roadway from huge main cables, which extend from one end of the bridge to the other. These cables rest on top of high towers and are secured at each end by anchorages. The towers enable the main cables to be draped over long distances.

Suppose that the maximum distance between two neighboring towers is D, and that the distance from the top of a tower to the roadway is H. Also suppose that the shape of a cable between any two neighboring towers is the same symmetric parabola (as shown in the figure). Now given B, the length of the bridge and L, the total length of the cables, you are asked to calculate the distance between the roadway and the lowest point of the cable, with minimum number of towers built (Assume that there are always two towers built at the two ends of a bridge).

## Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1T10) which is the number of test cases. T test cases follow, each preceded by a single blank line.

For each test case, 4 positive integers are given on a single line.

D
- the maximum distance between two neighboring towers;
H
- the distance from the top of a tower to the roadway;
B
- the length of the bridge; and
L
- the total length of the cables.

It is guaranteed that BL. The cable will always be above the roadway.

## Output

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

For each test case, print the distance between the roadway and the lowest point of the cable, as is described in the problem. The value must be accurate up to two decimal places.

## Sample Input

2

20 101 400 4042

1 2 3 4


## Sample Output

Case 1:
1.00

Case 2:
1.60


#include <cstdio>
#include <cmath>

double a;
double h;
double D1,L1;

double f(double x)
{
return sqrt(1.0+4.0*a*a*x*x);
}

double simpson(double a,double b)
{
double c = a+(b-a)/2;
return (f(a)+4*f(c)+f(b))*(b-a)/6;
}

double asr(double a,double b,double eps,double A)
{
double c = a+(b-a)/2;
double L = simpson(a,c) , R = simpson(c,b);
if (fabs(L+R-A) <= 15*eps) return L+R+(L+R-A)/15.0;
return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);
}

double asr(double a,double b,double eps)
{
return asr(a,b,eps,simpson(a,b));
}

double F(double w,double h)
{
a = 4.0*h/(w*w);
return 2*asr(0,w/2,1e-8);
}

double eps = 1e-8;

int main()
{
freopen("3485.in","r",stdin);
freopen("3485.out","w",stdout);

int T;
scanf("%d",&T);
int D,H,B,L;
int cases = 0;

while (scanf("%d%d%d%d",&D,&H,&B,&L)!=EOF)
{
cases ++;
double l = 0; double r = H;
int n = (B+D-1)/D;
D1 = double(B)/n;
L1 = double(L)/n;
while (r-l>1e-3)
{
h = (r+l)/2.0;
double rs = F(D1,h);

//printf("Debug F(%lf,%lf) = %lf\n",w,h,rs);
if (rs < L1-eps)
l = h;
else
r = h;
}

if (cases > 1) printf("\n");
printf("Case %d:\n%.2lf\n",cases,H-h);
}
return 0;
}

0
0

【套餐】嵌入式Linux C编程基础
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【套餐】深度学习入门视频课程——唐宇迪
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】计算机视觉原理及实战——屈教授
【直播】机器学习之凸优化——马博士
【直播】机器学习&数据挖掘7周实训--韦玮

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：326479次
• 积分：7186
• 等级：
• 排名：第3089名
• 原创：419篇
• 转载：14篇
• 译文：0篇
• 评论：32条
文章分类
最新评论