ACdream 1221 Little Jumper

Little Jumper

Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Submit Statistic Next Problem

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.

ACdream 1221 Little Jumper_第1张图片

      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
//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")


using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;

#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1;
    char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------


#define double long double
const double inf=1.0e40;
const double eps=1.0e-14;
const double zero=0.0;
const double one=1.0;
const double two=2.0;
const double three=3.0;

double b1,t1,b2,t2,l,ds,dt,g;

double calc(double d, double s, double b, double t)
{
    double c=d*(one-d/s);
    b=b/c;
    t=t/c; //cout<<b<<" "<<c<<endl;
    if(b>one)
        return g*s*(b+one/b)/two;
    else if(t<one)
        return g*s*(t+one/t)/two;
    else
        return g*s;
}

double getsp(double s)
{
    return max(calc(ds,ds+s,b1,t1),calc(dt,dt+l-s,b2,t2));
}

int main()
{
    while(cin>>b1>>t1>>b2>>t2>>l>>ds>>dt>>g)
    {
        double Left=zero, Right=l;
        for(int i=0; i<100; i++)
        {
            double mid=(Left*two+Right)/three;
            double midd=(Left+Right*two)/three;
            if(getsp(mid)<getsp(midd))
            {
                Right=midd;
            }
            else
            {
                Left=mid;
            }
        }
        cout<<setiosflags(ios::fixed);
        cout<<setprecision(8)<<sqrtl(getsp(Left))<<endl;
    }
    return 0;
}


你可能感兴趣的:(ACdream)