CodeForces 631C

设t时间最短,建方程,一元二次方程 ,分情况讨论最小值就行

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define maxn 9999999
#define eps 1e-6
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x1, y1, x2, y2;
	int vx1, vy1, vx2, vy2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	scanf("%d%d%d%d", &vx1, &vy1, &vx2, &vy2);
	ll a = 0, b = 0, c = 0;
	ll d1 = x1 - x2, d2 = y1 - y2, vd1 = vx1 - vx2, vd2 = vy1 - vy2;
	a = vd1*vd1 + vd2*vd2;
	b = 2 * d1*vd1 + 2 * d2*vd2;
	c = d1*d1 + d2*d2;
	double ans = 0;
	if (a == 0)
	{
		ans = sqrt(c);
	}
	else
	{
		//ll xx = b*b - 4 * a*c;
		double minx = -(b*1.0 / (2.0*a));
		if (abs(minx - 0) < eps || minx < 0)
		{
			ans = sqrt(c);
		}
		else
		{
			ans = sqrt(a*minx*minx + b*minx + c);
		}
	}
	printf("%.10f\n", ans);
	//system("pause");
	//while (1);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值