zoj 2340 Little Jumper(数学题,三分)

Little Jumper

Time Limit: 5 Seconds       Memory Limit: 32768 KB       Special Judge

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


题意:一只青蛙用任意速度和角度跳2次,由一个点跳入中间那段其中一个位置,再跳到固定点,问2次速度最大最小是多少
题解:代码里面有公式,又公式知,固定2点时,所需的最小速度为,v = sqrt(gl / 2),此时v随l增大而增大,所以第一次跳的速度随着中间落点往右而增大,相反第二次跳的速度随着中间落点往右而减小,所以这是一个凸函数,所以三分之
ps:若固定三分一个eps会wa。。。怎么都调不到,所以我又限定了至少三分88次。。。
       关于公式的详解在代码里面

#include <bits/stdc++.h>

using namespace std;

const double eps = 1e-10;

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

//prove: know l, when aofa = pi / 2, v is smallest
//konw g, set vx, vy, t
//l = vx * t, vy = g * t / 2
//t = l / vx = 2 * vy / g
//vx * vy = l * g / 2
//so v = sqrt(vx * vx + vy * vy) >= sqrt(2 * vx * vy) = sqrt(g * l)
//so when vx = vy, v get the smallest value, then aofa = pi / 2
//
//calculate: know l, aofa = pi / 2, when the point at s, cal h
//as above, vx * vy = g * l / 2, and vx = vy
//so vx = sqrt(g * l / 2), then v = sqrt(g * l)
//set now time is t
//then t = s / vx
//as konw, h = vy * t - g * t * t / 2
//           = vy * s / vx - g * s * s / (2 * vx * vx)
//           = s -  s * s / l
//
//however, sometime it is not satisfied b <= h <= t
//while h < b
//as we know it should pass point(s, b)
//so let t0 for the time pass point(s, b)
//then vx * t0 = s and vy * t0 - g * t0 * t0 / 2 = b
//so b = vy * s / vx - g * s * s / vx / vx / 2
//as above, vx * vy = g * l
// so vx * vx = g * s / 2 / b * (l - s)
// so vy * vy = b * g * l * l / 2 / s / (l - s)
// so v = sqrt(vx * vx + vy * vy)
//      = sqrt(g * s * (l - s) / 2 / b + g * l * l * b / (2 * s * (l - s)))
//
//while h > t, the same as above
//so v = sqrt(g * s * (l - s) / 2 / t + g * l * l * t / (2 * s * (l - s)))
//
//that's all

double get(double l, double s, double b, double t){
	double h = s - s * s / l;
	if(h < b){
		return sqrt(g * s * (l - s) / 2 / b + g * l * l * b / (2 * s * (l - s)));
	}
	else if(h > t){
		return sqrt(g * s * (l - s) / 2 / t + g * l * l * t / (2 * s * (l - s)));
	}
	else{
		return sqrt(g * l);
	}
}

double cal(double s){
	double temp = get(ds + s, ds, b1, t1);
	temp = max(temp, get(df + l - s, df, b2, t2));
	return temp;
}

int main(){

	freopen("in.txt", "r", stdin);
	while(cin >> b1 >> t1 >> b2 >> t2 >> l >> ds >> df >> g){
		double left = 0, right = l;
		int i = 0;
		while(right - left > eps || i++ < 88){
		//for(int i = 0; i < 100; i++){
			double mid1 = left + (right - left) / 3;
			double mid2 = right - (right - left) / 3;
			if(cal(mid1) < cal(mid2)) right = mid2;
			else left = mid1;
		}
		printf("%.6f\n", cal(left));
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值