题目链接
You maybe have ACed a question about computational geometry,which describes two dogs’ journey and calculate the shortest distance between them. Now, I provide a easier problem about two pigs. heir path are half-lines. When they start running, they won’t stop. Why? Because they can’t take a sudden turn.
So, I provide the start points of two pigs and their velocities. Please tell me the shortest distance between them.
We purpose that two pigs start running at the same time and will not stop because they are running in an vast grasslane without any tree.
If they smash into each other, the answer is zero and ignore the influence.
The first line is an integer T which indicates the number of cases. For each case, first line is four numbers x1,y1,x2,y2, indicate the start points of two pigs(x1,y1), (x2,y2). The second line is four numbers u1,v1,u2,v2, indicate the velocities of two pigs(u1,v1),(u2,v2). T <= 1000 The absolute value of x1,y1,x2,y2,u1,v1,u2,v2 will not lager than 1000.
For each case, you should output one line like ”Case i: d”. i stands for the case number and d stands for the answer, which should rounded to 6 decimal places.
在二维坐标系上,给出两个点的起始位置和速度(向量表示),求两点最近时的距离
由已知条件推出两点坐标与时间的关系:A(x1+v1*t,y1+u1*t),B(x2+v2*t,y2+u2*t),再用距离公式得到一个距离跟时间的二次函数,然后就是二次函数求最小值的问题了,这里开口必定向上,特判一下a=0也就是速度相等的情况就可以啦