IX Samara Regional Intercollegiate Programming Contest F 三分



链接:戳这里


F. Two Points
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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, y2 ( - 104 ≤ x1,  y1,  x2,  y2 ≤ 104) — the coordinates of the points.

The second line contains four space-separated integers vx1, vy1, vx2, vy2 ( - 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


题意:

给出两个方向的射线以及速度  问哪个时间段两点之间的距离最短,输出最短距离


思路:

列出方程式关于一个一元二次方程,三分找出极值


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
ll a1,a2,b1,b2,c1,c2,d1,d2;
const long double eps=1e-8;
int dcmp(long double x)
{
    if(fabs(x)<=eps) return 0;
    return x<0?-1:1;
}
int main()
{
    cin>>a1>>a2>>b1>>b2;
    cin>>c1>>c2>>d1>>d2;
    ll e1=b1-a1;
    ll e2=d1-c1;
    ll f1=b2-a2;
    ll f2=d2-c2;
    ll A=e2*e2+f2*f2;
    ll B=2*e1*e2+2*f1*f2;
    ll C=e1*e1+f1*f1;
    double l=0.0,r=1e8*1.0,mid;
    while(r-l>1e-10){
        double m1=l+(r-l)/3;
        double m2=r-(r-l)/3;
        double calc1=A*m1*m1+B*m1+C;
        double calc2=A*m2*m2+B*m2+C;
        if(calc1<calc2) r=m2;
        else l=m1;
    }
    double ans=A*l*l+B*l+C;
    if(ans>=0.00) printf("%.12f\n",sqrt(ans));
    else printf("%.12f\n",sqrt(C*1.0));
    return 0;
}
/*
0 0 0 3
0 1 0 -2
*/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值