题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=204
题意:给出下图中的参数。从A跳到B。在A起跳速度为v1,在中间起跳速度为v2。求min(max(v1,v2))。
思路:在两个木板之间的位置是单峰函数,三分。
const double EPS=1e-12;
double b1,t1,b2,t2,L,ds,df,g;
double cal(double x1,double y1,double x2)
{
double a=y1/(x1*x1-x1*x2);
return -g*a*x2*x2/2-g/(2*a);
}
double cal(double b1,double t1,double L1,double L2)
{
double ans=min(cal(L1,b1,L1+L2),cal(L1,t1,L1+L2));
double p=L1+L2,temp=g*p,y=L1*L2/p;
if(y>=b1&&y<=t1) ans=temp;
return ans;
}
double cal(double x)
{
return max(cal(b1,t1,ds,x),cal(b2,t2,L-x,df));
}
int main()
{
while(cin>>b1>>t1>>b2>>t2>>L>>ds>>df>>g)
{
double low=EPS,high=L,mid1,mid2,x,y;
while(high-low>1e-12)
{
mid1=(low+high)*0.5;
mid2=(mid1+high)*0.5;
x=cal(mid1);
y=cal(mid2);
if(x<y) high=mid2;
else low=mid1;
}
double ans=min(cal((low+high)*0.5),min(cal(low),cal(high)));
printf("%.4lf\n",sqrt(ans));
}
return 0;
}