Codeforces Round #327 (Div. 2)D. Chip 'n Dale Rescue Rangers

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road.

We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2).

Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed  meters per second.

Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after  seconds the new position of the dirigible will be .

Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer.

It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air.

Input

The first line of the input contains four integers x1y1x2y2 (|x1|,  |y1|,  |x2|,  |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively.

The second line contains two integers  and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively.

Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that  and .

Output

Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample test(s)
input
0 0 5 5
3 2
-1 -1
-1 0
output
3.729935587093555327
input
0 0 0 1000
100 1000
-50 0
50 0
output
11.547005383792516398

题意:我们在(x1,y1),要前往(x2,y2)。最大速度为V。前在T秒的时间里,我们会被强制加上一个(vx,vy)的速度, 在T秒之后的时间里,我们会被加上(wx,wy)的速度, 
我们可以任意改变速度的大小和方向,只是不能超过V。 现在问你,最早到达(x2,y2)的时间是什么。 

方法一:

刚开始想的是两点之间直线最短。t时刻前把v分解大小和方向为(vxx, vyy)(vxx*vxx+vyy*vyy=v*v),此时时刻的速度为(vxx+vx, vyy+vy),使这个速度方向与从起点到终点的方向相同。

t时刻后采用类似的方法。

这样就有了两个方程,就可以求出最大的实际速度(相对于风的速度)。就可以直接求时间了。但是数学太差,容易出错。


方法二:

采用二分的思想。

(xn, yn)表示T时刻时风移动的位置

(xn, yn)到(x2,y2)<=T*v是就可以。

否者时间短了

//二分
#include 
   
   
    
    
#include 
    
    
     
     
using namespace std;

double v, t;
double vx, vy, wx, wy;
double xx, yy;

bool check(double tmp)
{
    double c;
    if(tmp < t)
    {
        double x = xx - vx*tmp;
        double y = yy - vy*tmp;
        c = x*x+y*y;
        return c <= tmp*v*tmp*v?true:false;
    }
    else
    {
        double x = xx - vx*t - (tmp-t)*wx;
        double y = yy - vy*t - (tmp-t)*wy;
        c = x*x+y*y;
        return c <= tmp*v*tmp*v?true:false;
    }
}

int main(void)
{
    ios::sync_with_stdio(false);
    cout.precision(10);
    double x1, y1, x2, y2;
    while(cin >> x1 >> y1 >> x2 >> y2)
    {
        cin >> v >> t;
        cin >> vx >> vy >> wx >> wy;
        xx = x2 - x1;
        yy = y2 - y1;
        yy = y2 - y1;
        double l = 0.0, r = 1e9;
        while(r - l >= 1e-7)
        {
            double mid = (l+r)/2;
            if(check(mid))
            {
                r = mid;
            }
            else
            {
                l = mid;
            }
        }
        cout << l << endl;
    }
    return 0;
}

    
    
   
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值