codeforces GYM 100971F 公式题或者三分

本文介绍了一种计算平面上两点随时间变化而产生的最小距离的方法。通过给定两点的初始位置及速度,利用一元二次方程求解两点间最短距离。文中提供了一个具体的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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\n",sqrt(ans));
    else
    printf("%.6f\n",sqrt(fc));
    return 0;
}

 

转载于:https://www.cnblogs.com/jhz033/p/5661279.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值