【二分】【自适应Simpson】Bridge

原创 2013年12月03日 12:01:25

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

\epsfbox{p3485.eps}

Input 

Standard input will contain multiple test cases. The first line of the input is a single integer T (1$ \le$T$ \le$10) 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 B$ \le$L. 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


写出抛物线方程,注意到弧长关于h单调递增,因此可以二分。列出弧长的计算公式,积分用自适应Simpson计算。

当每个抛物线的宽度最大时, 支柱个数最少。

注意比较的时候和L/n比较,因为L是总长度,而L/n才是抛物线的弧长。

二分出h,然后比较计算出来的弧长和要求的弧长,调整区间。


我把二分区间最小值设为10^-3,其实不太好,因为近似算法本身存在一定误差,而且近似出的结果和宽度的比较也有一定误差,所以最好把区间最小值设得更小一些。

小心最后不能多输回车。

#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;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

zoj2614 Bridge(自适应Simpson公式+二分答案)

【题解】 首先求出分出的最少区间数:n=ceil(B/D),ceil():向上取整 然后依据每一段的宽度w=B/n及弧长L/=n来求"深度"h即可,答案为:y=H-h w,h可确定一条抛物线,其弧长L...

CSU 1806 Toll (自适应Simpson积分 )

题意:就是一个积分+最短路分析:学到的新知识:自适应SimpsonSimpson积分 ∫baf(x)dx≈F(a,b)=(b−a)6[f(a)+4f(a+b2)+f(b)] {\int_a^bf(x...

hdoj-1724 Ellipse(自适应Simpson积分)

浙大月赛的时候卡在了一道积分题目上,被积函数无法求出原函数。 连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3898 ...

【计算几何】【simpson自适应公式】【NOI2004】降雨量

【问题描述】 M国是个多雨的国家,尤其是P城,频繁的降雨给人们的出行带来了不少麻烦。为了方便行人雨天过马路,有关部门在每处人行横道的上空都安装了一种名为“自动伞”的装置。(如图1所示) 每把自动伞都...
  • Whjpji
  • Whjpji
  • 2012-06-11 15:37
  • 2136

【计算几何】【simpson自适应公式】【NOI2009】描边

【问题描述】 小Z自幼就酷爱数学。聪明的他特别喜欢研究一些数学小问题。 有一天,小Z在一张纸上选择了n个点,并用铅笔将它们两两连接起来,构成n(n-1)/2条线段。由于铅笔很细,可以认为这些线段的宽度...
  • Whjpji
  • Whjpji
  • 2012-05-22 10:42
  • 1046

自适应simpson公式解定积分

来自白书 ,

HDU - 4498 Function Curve 自适应simpson

题目链接:点击打开链接 题意:求题目中F(x)的弧长 思路:求出各个二次函数的交点并保存起来,然进行排序,然后按各个交点求出以这个点为端点的一段最小的函数,并求出这个函数在这个区间的弧长。弧长当然...

学习笔记: 自适应Simpson积分

看了一些大牛的博客,终于对自适应Simpson积分有了初步的了解。 Q:自适应Simpson积分是用来做什么的? A:用来求积分啊! Q:它和一般的微积分有什么区别? A:不能求出精确解,但是可...

HUST 1360 Solve the integration 自适应simpson积分模板题

1360 - Solve the integration Time Limit: 1s Memory Limit: 256MB Submissions: 203 Solved: 53 Des...

BZOJ 1502 [NOI2005]月下柠檬树 自适应Simpson积分

BZOJ 1502 [NOI2005]月下柠檬树 自适应Simpson积分
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)