There are N N points in total. Every point moves in certain direction and certain speed. We want to know at what time that the largest distance between any two points would be minimum. And also, we require you to calculate that minimum distance. We guarantee that no two points will move in exactly same speed and direction.
The first line has a number T T ( T≤10 T≤10) , indicating the number of test cases.
For each test case, first line has a single number N N ( N≤300 N≤300), which is the number of points.
For next
N
N lines, each come with four integers
Xi
Xi,
Yi
Yi,
VXi
VXi and
VYi
VYi (
−106≤Xi
−106≤Xi,
Yi≤106
Yi≤106,
−102≤VXi
−102≤VXi,
VYi≤102
VYi≤102), (
Xi
Xi,
Yi
Yi) is the position of the
ith
ith point, and (
VXi
VXi,
VYi
VYi) is its speed with direction.
That is to say, after
1
1 second, this point will move to (
Xi+VXi
Xi+VXi,
Yi+VYi
Yi+VYi).
For test case
X
X, output Case #X:
first, then output two numbers, rounded to
0.01
0.01, as the answer of time and distance.
2
2
0 0 1 0
2 0 -1 0
2
0 0 1 0
2 1 -1 0
Case #1: 1.00 0.00
Case #2: 1.00 1.00
/*【题意】:
02
给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小值的时刻
03
解析:
04
两个点为例,任意两个点,按照自己的方向移动,一般情况下是,先两点慢慢接近,直到最近距离,然后慢慢远离,后面越来越远,图像画出来有点像抛物线,
05
这题就是抛物线求最小值,三分:先二分时间,按照斜率确定移动方向,直到移动到抛物线的最低端
06
注意题目精度,每次最好分1e-5以上,才能保证正确性
07
*/
#include <iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
const int N=330;
const double eps=1e-6;
double x[N];
double y[N];
double vx[N];
double vy[N];
int n;
double calt(double t)//最长路径
{
double sum=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
double x1=x[i]+vx[i]*t;
double y1=y[i]+vy[i]*t;
double x2=x[j]+vx[j]*t;
double y2=y[j]+vy[j]*t;
sum=max(sum,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
return sum;
}
double sanfen()//最短时间//求凹凸线性的极值
{
double l=0,r=1e10;
while(r-l>=eps)
{
double mid=(l+r)/2;
double midmid=(mid+r)/2;//三分时间
double tmp1=calt(mid);
double tmp2=calt(midmid);
if(tmp2>tmp1)//舍弃右区间
r=midmid-eps;
else//舍弃左区间
l=mid+eps;
}
return l;
}
int main()
{
int t;
cin>>t;
for(int k=1;k<=t;k++)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>x[i]>>y[i]>>vx[i]>>vy[i];
double h=sanfen();
printf("Case #%d: %.2lf %.2lf\n",k,h,calt(h));
}
}