D. Follow Traffic Rules

来源:互联网 发布:算法博弈论中文版 pdf 编辑:程序博客网 时间:2024/05/16 19:16

D. Follow Traffic Rules
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed.

It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of a km/h2, and has maximum speed of v km/h. The road has the length of l km, and the speed sign, limiting the speed to w km/h, is placed d km (1 ≤ d < l) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed.

The car can enter Bercouver at any speed.

Input

The first line of the input file contains two integer numbers a and v (1 ≤ a, v ≤ 10000). The second line contains three integer numbers ld and w (2 ≤ l ≤ 100001 ≤ d < l1 ≤ w ≤ 10000).

Output

Print the answer with at least five digits after the decimal point.

Examples
input
1 12 1 3
output
2.500000000000
input
5 70200 170 40
output
8.965874696353

题意:

有一条公路,长度为l,在距离d处的地方有一个检查速度的装置,这个装置要求通过这一点时的速度不能高于限定的速度w,有一辆车的最大行驶速度是v,加速度是a(加减的加速度一样),问这个车从公路的起点出发,不违章的情况下,最少需要多长时间


题解:

可以说是物理题+数学题,难点在于要把所有的过程考虑清楚,每一步怎么处理,细节太多,本来思路是清晰的,一见到wa,可能一慌就混乱了,一定要注意心态,虽然一上午只做了一道题,但是感觉这样也许对自己的心性也是一种锻炼吧

 

/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;double slove(double a,double b,double c)//一元二次方程的正解{    return (-b+sqrt(b*b-4*a*c))/(2*a);}int main(){    double a,v,len,d,w,ans=0;    scanf("%lf%lf%lf%lf%lf",&a,&v,&len,&d,&w);    if(w>=v||w*w/(2*a)>d)//不会超速,可以一直加速跑    {        double x=(v*v)/(2*a);//加满速需要的距离        if(x>=len)//一直加速下去        {            ans+=sqrt(2*a*len)/a;//加速时间        }        else        {            ans+=(len-x)/v+v/a;        }    }    else//有超速的可能    {        len-=d;//单独讨论限速段        double tx=w*w/(2*a);//加速到限定速度需要的距离        double t=w/a;//加速到限定速度的时间        d-=tx;//限速段其余的路程        ans+=t;d/=2;        tx=(v*v-w*w)/(2*a);        if(tx>d)//没有加速到最高速        {            double tv=sqrt(2*a*d+w*w);            ans+=2*(tv-w)/a;        }        else        {            ans+=2*(v-w)/a+2*(d-tx)/v;//加速到满后匀速        }        //过了限速段后        tx=(v*v-w*w)/(2*a);        if(tx>len)//没有加速到最高速        {            double tv=sqrt(2*a*len+w*w);            ans+=(tv-w)/a;        }        else        {            ans+=(v-w)/a+(len-tx)/v;//加速到满后匀速        }    }    printf("%.12lf\n",ans);    return 0;}


0 0
原创粉丝点击