问题稍作简化就可以看成已知一条抛物线的宽度和长度,求它的高度。
这个问题并不好求,但是如果已知高度和宽度,求抛物线的长度就是一个很简单的积分了。因此我们可以二分答案。
设宽度为w,高度为
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-6;
int D,H,B,L;
double w,a;
double F(double x)
{
return sqrt(a*x*x+1);
}
double get(double l,double r)
{
double mid=(l+r)/2;
return (r-l)*(F(l)+F(r)+4*F(mid))/6;
}
double sim(double l,double r,double val)
{
double mid=(l+r)/2,x=get(l,mid),y=get(mid,r);
if (fabs(val-x-y)<eps) return val;
return sim(l,mid,x)+sim(mid,r,y);
}
double cal(double x)
{
a=64*x*x/(w*w*w*w);
return sim(-w/2,w/2,get(0,w/2));
}
void solve()
{
int n;
double l,r,mid;
scanf("%d%d%d%d",&D,&H,&B,&L);
n=B/D+((B%D)?1:0);
w=(double)B/n;
l=0;
r=H;
while (r-l>eps)
{
mid=(l+r)/2;
if (cal(mid)*n<L) l=mid;
else r=mid;
}
printf("%.2f\n",H-l);
}
int main()
{
int T;
scanf("%d",&T);
for (int K=1;K<=T;K++)
{
if (K>1) putchar('\n');
printf("Case %d:\n",K);
solve();
}
}