Codeforces 591D Chip 'n Dale Rescue Rangers【思维+二分】

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 .

Examples
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);问我们需要航行多长时间到达目的地。


思路:


①首先我们能够确定,如果时间t能够到达目的地的话,那么t+1时刻也能够到达目的地。所以我们二分一个时间,来check一下即可。


②对于当前枚举的时间mid,我们计算mid时间内,从起点被风所影响能够到达的点(posx,posy),然后计算(posx,posy)和终点的距离,如果我们有:v*mid>=dist,那么对应时间mid内一定能够到达终点,同时减少R,继续二分即可。


过程维护一下。


Ac代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double x1,y1,x2,y2,v,t,vx,vy,wx,wy;
    while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&v,&t,&vx,&vy,&wx,&wy))
    {
        double ans=0;
        double l=0;
        double r=1e9;
        for(int i=0;i<120;i++)
        {
            double mid=(l+r)/2;
            double posx=x1+min(t,mid)*vx+max(mid-t,0.0)*wx;
            double posy=y1+min(t,mid)*vy+max(mid-t,0.0)*wy;
            double dist=sqrt((posx-x2)*(posx-x2)+(posy-y2)*(posy-y2));
            if(v*mid>=dist)r=mid,ans=mid;
            else l=mid;
        }
        printf("%.12lf\n",ans);
    }
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值