acdream1221Little Jumper+三分

Problem Description

  Little frog Georgie likes to jump. Recently he have discovered the new playground that seems the perfect place to jump.

  Recently the new jumping exercise has become very popular. Two vertical walls are placed on the playground, each of which has a hole.

  The lower sides of the holes in the walls are on heights b1 and b2 respectively, and upper sides on heights t1 and t2. Walls are parallel and placed on distance l from each other.

  The jumper starts at the distance ds from the first wall. It jumps through the first hole and lands between the walls. After that from that point he jumps through the second hole. The goal is to land exactly at the distance df from the second wall.

这里写图片描述
Let us describe the jump. The jumper starts from the specified point and starts moving in some chosen direction with the speed not exceeding some maximal speed v, determined by the strength of the jumper. The gravity of g forces him down, thus he moves along the parabolic trajectory.

  The jumper can choose different starting speeds and different directions for his first and second jump.

  Of course, The jumper must not attempt to pass through the wall, although it is allowed to touch it passing through the hole, this does not change the trajectory of the jump. The jumper is not allowed to pass through both holes in a single jump.

  Find out, what must be the maximal starting speed of the jumper so that he could fulfil the excersise.

Input

  Input file contains one or more lines, each of which contains eight real numbers, separated by spaces and/or line feeds. They designate b1, t1, b2, t2, l, ds, df and g. All numbers are in range from 10-2 to 103, t1 ≥ b1 + 10-2, t2 ≥ b2 + 10-2.

  Input file contains at most 1000 test cases.

Output
For each line of the input file output the smallest possible maximal speed the jumper must have to fulfil the exercise. If it is impossible to fulfil it, output -1. Your answer must be accurate up to 10-4.
Sample Input

0.3 1.0 0.5 0.9 1.7 1.2 2.3 9.8
0.6 0.8 0.6 0.8 2.4 0.3 1.5 0.7

Sample Output

5.2883
1.3127

Source
Andrew Stankevich Contest 2

假象得到,在两柱子之间的位置是单峰函数。。so..中间是下边那些函数计算。。

我们知道球的起点x0,落地点x1,我们可以设曲线方程 y=k(xx0)(xx1)
首先出射45度是最远的此时的 k=1x1x0
其他情况要经过 (x,y) 的话有 k=y(xx0)(xx1)

然后之后由抛物线的k来确定v
最高点: h=y(x0+x12)=k(x0x1)(x0x1)4
由时间等式: v2y=2gh
水平距离等式: 2vxvy=(x1x0)g
so…………
vy=2gh
vx=(x1x0)g2vy

#include<bits/stdc++.h>
using namespace std;
#define eps 1e-12

double b1,t1,b2,t2,l,ds,df,g;
//左坐标,右坐标,位置,最低,最高
double mv(double x0,double x1,double wz,double b,double t){
    double jian=x1-x0;
    double y=-1.0/(x1-x0)*(wz-x0)*(wz-x1); //45度飞出去
    double k,vx,vy,minv,h;
    if(b<=y&&y<=t){
        k=1.0/(x1-x0);
        h=k*(x1-x0)*(x1-x0)/4;
        vy=sqrt(2*g*h),vx=jian*g/2.0/vy;
        return sqrt(vy*vy+vx*vx);
    }
    k=-t/((wz-x0)*(wz-x1));//从上边穿过
    h=k*(x1-x0)*(x1-x0)/4;
    vy=sqrt(2*g*h),vx=jian*g/2.0/vy;
    minv=sqrt(vy*vy+vx*vx);

    k=-b/((wz-x0)*(wz-x1));//从下边穿过
    h=k*(x1-x0)*(x1-x0)/4;
    vy=sqrt(2*g*h),vx=jian*g/2.0/vy;
    return min(minv,sqrt(vy*vy+vx*vx));
}
double maxv(double x){
    return max(mv(0,ds+x,ds,b1,t1),mv(ds+x,ds+l+df,ds+l,b2,t2));
}
int main(){
    while(cin>>b1>>t1>>b2>>t2>>l>>ds>>df>>g){
        double L=0,R=l;
        while(fabs(R-L)>eps){
            double m1=(2*L+R)/3.0;
            double m2=(L+2*R)/3.0;
            if(maxv(m1)<maxv(m2)) R=m2;
            else L=m1;
        }
        printf("%.4f\n",maxv((L+R)/2));
    }
    return 0;
}

顺便附上一个其他菊苣写的。。太强了。。

//宽度,位置,最低,最高
double calc(double x,double c,double b,double t)
{
    double y = c - c*c/x;  //
    double p = c*(x-c);
    if(y<b)
        return sqrt(g*p/2/b+g*x*x*b/2/p);
    if(y>t)
        return sqrt(g*p/2/t+g*x*x*t/2/p);
    return sqrt(g*x);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值