zoukankan      html  css  js  c++  java
  • codeforces GYM 100971F 公式题或者三分

    F. Two Points
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are two points (x1, y1) and (x2, y2) on the plane. They move with the velocities (vx1, vy1) and (vx2, vy2). Find the minimal distance between them ever in future.

    Input

    The first line contains four space-separated integers x1, y1, x2, y( - 104 ≤ x1,  y1,  x2,  y2 ≤ 104) — the coordinates of the points.

    The second line contains four space-separated integers vx1, vy1, vx2, vy( - 104 ≤ vx1,  vy1,  vx2,  vy2 ≤ 104) — the velocities of the points.

    Output

    Output a real number d — the minimal distance between the points. Absolute or relative error of the answer should be less than 10 - 6.

    Examples
    input
    1 1 2 2
    0 0 -1 0
    output
    1.000000000000000
    input
    1 1 2 2
    0 0 1 0
    output
    1.414213562373095
    题意:给你两个点的位置与x轴方向的速度,y轴方向的速度,求两个点最近的距离;
    思路:根据题意:得到两个相差x的距离的平方+y轴相差距离的平方得到一元二次方程;
       利用公式得到最小值;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 100000007
    #define esp 0.00000000001
    const int N=2e5+10,M=1e6+10,inf=1e9;
    int main()
    {
        double x,y,a,b,z,i,t;
        double vx,vy,va,vb;
        cin>>x>>y>>a>>b;
        cin>>vx>>vy>>va>>vb;
        double fa,fb,fc;
        fa=(vx-va)*(vx-va)+(vy-vb)*(vy-vb);
        fb=2.0*((vb-vy)*(b-y)+(va-vx)*(a-x));
        fc=(a-x)*(a-x)+(b-y)*(b-y);
        double ans=(4*fa*fc-fb*fb)/(4*fa);
        double zuo=-fb/(2.0*fa);
        if(zuo>=0.0)
        printf("%.6f
    ",sqrt(ans));
        else
        printf("%.6f
    ",sqrt(fc));
        return 0;
    }
  • 相关阅读:
    9IDEA常见的快捷键
    8Java类与对象
    5Java运算符
    10Java面向对象中级
    3Java基础
    4Java基础变量
    6Java控制结构
    7Java数组
    11Java面向对象高级
    缓存事件过期监听机制
  • 原文地址:https://www.cnblogs.com/jhz033/p/5661279.html
Copyright © 2011-2022 走看看