题意:我们在(x1,y1),要前往(x2,y2)。最大速度为V。前在T秒的时间里,我们会被强制加上一个(vx,vy)的速度, 在T秒之后的时间里,我们会被加上(wx,wy)的速度,
我们可以任意改变速度的大小和方向,只是不能超过V。 现在问你,最早到达(x2,y2)的时间是什么。
方法一:
刚开始想的是两点之间直线最短。t时刻前把v分解大小和方向为(vxx, vyy)(vxx*vxx+vyy*vyy=v*v),此时时刻的速度为(vxx+vx, vyy+vy),使这个速度方向与从起点到终点的方向相同。
t时刻后采用类似的方法。
这样就有了两个方程,就可以求出最大的实际速度(相对于风的速度)。就可以直接求时间了。但是数学太差,容易出错。
方法二:
采用二分的思想。
(xn, yn)表示T时刻时风移动的位置
(xn, yn)到(x2,y2)<=T*v是就可以。
否者时间短了
//二分
#include
#include
using namespace std;
double v, t;
double vx, vy, wx, wy;
double xx, yy;
bool check(double tmp)
{
double c;
if(tmp < t)
{
double x = xx - vx*tmp;
double y = yy - vy*tmp;
c = x*x+y*y;
return c <= tmp*v*tmp*v?true:false;
}
else
{
double x = xx - vx*t - (tmp-t)*wx;
double y = yy - vy*t - (tmp-t)*wy;
c = x*x+y*y;
return c <= tmp*v*tmp*v?true:false;
}
}
int main(void)
{
ios::sync_with_stdio(false);
cout.precision(10);
double x1, y1, x2, y2;
while(cin >> x1 >> y1 >> x2 >> y2)
{
cin >> v >> t;
cin >> vx >> vy >> wx >> wy;
xx = x2 - x1;
yy = y2 - y1;
yy = y2 - y1;
double l = 0.0, r = 1e9;
while(r - l >= 1e-7)
{
double mid = (l+r)/2;
if(check(mid))
{
r = mid;
}
else
{
l = mid;
}
}
cout << l << endl;
}
return 0;
}