您的位置:首页 > 其它

CodeForces 631C

2016-07-15 17:59 483 查看
设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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: