2015
09-17

# The Moving Points

There are 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 rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).

The rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).

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

/*【题意】：

注意题目精度，每次最好分1e-5以上，才能保证正确性
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=310;
#define exp  1e-6
int n;
struct point
{
double x,y;
double vx,vy;
}p[maxn];
double dis(int a,int b,double k)
{
return sqrt( 1.0*(p[a].x+p[a].vx*k-p[b].x-p[b].vx*k)*(p[a].x+p[a].vx*k-p[b].x-p[b].vx*k)+
1.0*(p[a].y+p[a].vy*k-p[b].y-p[b].vy*k)*(p[a].y+p[a].vy*k-p[b].y-p[b].vy*k) );
}
double okboy(double k)
{
int i,j;
double max=-1;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
double sb=dis(i,j,k);
if(sb>max) max=sb;
}
}
return max;
}
void sanfen()
{
double l=0,r=1e8,min=(double)0x3f3f3f3f,t,mid;
while(l<r)
{
mid=(l+r)/2;
double ok1=okboy(mid);
double ok2=okboy(mid-exp);//三分时间
if(ok1<ok2) l=mid+exp;
else r=mid-exp;
if(min>ok1)
{
min=ok1;
t=mid;
}
}
printf("%.2lf %.2lf\n",t,min);
}
int main()
{
int i;
int t,cas=0;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy);
printf("Case #%d: ",++cas);
sanfen();
}
return 0;
}