【题意】
修建一座桥。桥上等距离放着若干个塔,塔高H,宽度不计。相邻两座塔之间的距离不能超过D。他之间的绳索形成全等的对称抛物线。桥长B,绳总长L,求建最少塔时绳索最下端离地高度y。
【题解】
需要用到微积分的一些东西。
最大划分数为:if(B%D==0) n=B/D;else n=B/D+1;
则可求出每段宽度和每段弧长:w=(double)B/(2.0*n);
L1=(double)L/(2.0*n);
以曲线最低点建立坐标系,假设宽w时高度为h,则抛物线方程可知为:y=h/(w*w)*x^2.
弧长公式L=定积分sqrt(1+(y‘)^2);而且弧长随着h的增加而增加是单调的。
二分枚举h即可。至于定积分的计算可以使用自适应simpson算法。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int B,D,L,H;
int n;
double h,w,L1;
struct Integral
{
double F(double x)//函数
{
double t=2*h*x/(w*w);
return sqrt(1+t*t);
}
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)//入口[a,b]积分,eps精度
{
return asr(a,b,eps,simpson(a,b));
}
};
int main()
{
int sec;scanf("%d",&sec);
for(int z=1;z<=sec;z++)
{
scanf("%d%d%d%d",&D,&H,&B,&L);
Integral ff;
if(B%D==0) n=B/D;else n=B/D+1;
w=(double)B/(2.0*n);
L1=(double)L/(2.0*n);
//二分
double h1=0,h2=H;
while(fabs(h1-h2)>=1e-6)
{
h=h1+(h2-h1)/2.0;
double ans=ff.asr(0,w,1e-8);
if(ans<L1)h1=h;else h2=h;
}
printf("Case %d:\n",z);//WA
printf("%.2f\n",H-h);
if(z!=sec)printf("\n");//WA
}
return 0;
}