CodeForces 590B

题意:救援队从(x1,y1)开飞船到(x2,y2)处救援,在飞船的最快速度为v,在时间t前,风的向量为(vx,vy),

过后风改变方向为(wx,wy),求救援队到(x2,y2)的最短时间。

题解:首先设飞船的速度为0,那么在时间h后,飞船最风的作用下到达(x,y),

这时我们只需判断在h时间内飞船能否从(x,y)到达(x1,y1);

这样我们就可以二分时间,找到最短的时间。

#include <iostream>
#include <cstdio>

using namespace std;

double x1,y1,x2,y2;
double v,t;
double vx,vy,wx,wy;

int solve(double h)
{
    //cout<<h<<endl;
    double x,y;
    if(h>t)
    {
        x=x1+vx*t+wx*(h-t);
        y=y1+vy*t+wy*(h-t);
    }
    else
    {
        x=x1+vx*h;
        y=y1+vy*h;
    }
    //cout<<x*x+y*y<<' '<<v*v*h*h<<endl;
    return (x-x2)*(x-x2)+(y-y2)*(y-y2)<=v*v*h*h;
}

int main()
{
    cin>>x1>>y1>>x2>>y2;
    cin>>v>>t;
    cin>>vx>>vy>>wx>>wy;
    double l=0,r=1e10;
    while((r-l)>=1e-6)
    {
        double mid=(l+r)/2;
        if(solve(mid))
            r=mid;
        else l=mid;
    }
    printf("%.18lf\n",l);
}

 

posted on 2016-05-25 22:04  猫哥小俊  阅读(155)  评论(0编辑  收藏  举报

导航