zoukankan      html  css  js  c++  java
  • Codeforces 590B Chip 'n Dale Rescue Rangers

    B. 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 firstt 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


    这个是昨天下午的cf div2 D题

    当时没搞明白怎么做 想了一个三分t时间的选择的vx,可以求出vy,这样t时间时的到达坐标可以求出来 就可以求出来从该坐标到终点还需要的时间t2  t+t2就是答案

    但是写的时候遇到了一个很大的问题 就是向量的方向问题

    可以求出来vx 但是vy用sqrt(vmax*vmax-vx*vx)时 有两个方向

    而且vx本身也有两个方向 和路径x同向或者反向

    所以写起来特别麻烦 今天搞到一半又放弃了


    后来仔细想了下 如果我们把航行和风速分开考虑

    t时间内航行到的点是以fx fy为圆心 t*vmax为半径的圆上的点

    而t时间内风速的作用 使得这个圆整体向 vx*t vy*t移动

    所以可以求出来t时间时的所有可以到达的点 它是一个平移之后的圆

    如果终点在这个圆内,则时间t内可以到达

    否则就得在时间t之后到达

    时间t后

    风速对终点的影响 相当于把终点往 -wx*t,-wy*t移动

    二分一下答案求起点终点距离等于两半径之和的时间 就是答案


    #include<bits/stdc++.h>
    using namespace std;
    int fx,fy,tx,ty;
    double vmax;
    double t;
    double vx,vy,wx,wy;
    double xx1,yy1,xx2,yy2;
    double rr1,rr2;
    double sqr(double k)
    {
        return k*k;
    }
    double dis(double fx,double fy,double tx,double ty)
    {
        return sqrt(sqr(tx-fx)+sqr(ty-fy));
    }
    void bs1()
    {
        double l=1e-11,r=t,mid,ans;
        ans=0;
        while(r>=l+1e-9)
        {
            mid=(l+r)/2;
            xx1=fx+vx*mid;
            yy1=fy+vy*mid;
            rr1=vmax*mid;
            //cout<<"t="<<t<<endl;
            //cout<<"xx1="<<xx1<<" yy1="<<yy1<<" rr1="<<rr1<<endl;
            if(dis(xx1,yy1,xx2,yy2)<=rr1)
            {
                ans=mid;
                r=mid;
            }
            else
                l=mid;
        }
        printf("%.17lf
    ",ans);
    }
    
    void bs2()
    {
        double l=1e-11,r=1e11,mid,ans;
        ans=0;
        while(r>=l+1e-9)
        {
            mid=(l+r)/2;
            xx2=tx-wx*mid;
            yy2=ty-wy*mid;
            rr2=vmax*mid;
            if(dis(xx1,yy1,xx2,yy2)<=rr1+rr2)
            {
                ans=mid;
                r=mid;
            }
            else
                l=mid;
        }
        printf("%.17lf
    ",ans+t);
    }
    int main()
    {
        cin>>fx>>fy>>tx>>ty>>vmax>>t>>vx>>vy>>wx>>wy;
        xx1=fx+vx*t;
        yy1=fy+vy*t;
        rr1=vmax*t;
        xx2=tx;
        yy2=ty;
        //cout<<xx1<<" "<<yy1<<" "<<rr1<<endl;
        if(dis(xx1,yy1,xx2,yy2)<=rr1)
            bs1();
        else
            bs2();
        return 0;
    }
    



  • 相关阅读:
    Solr服务在Linux上的搭建详细教程
    Linux服务器上安装JDK小白教程
    request和response中文乱码问题后台处理办法
    Redis的五种数据类型及方法
    Java类装载器ClassLoader
    Git快速入门和常用命令
    redis在Linux上的部署和jedis简单使用
    Linux常用基础命令
    JDK1.7中HashMap底层实现原理
    微信电脑版无法显示图片无法下载文件
  • 原文地址:https://www.cnblogs.com/abgnwl/p/6550333.html
Copyright © 2011-2022 走看看