Description

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.
 

Input

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 X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
 

Output

For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
 

Sample Input

2 2 0 0 1 0 2 0 -1 0 2 0 0 1 0 2 1 -1 0
 

Sample Output

Case #1: 1.00 0.00 Case #2: 1.00 1.00
 
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int X[310],Y[310],VX[310],VY[310],N;

double find(double t)
{
    double maxs=0;
    for(int i=0;i<N;i++)
        for(int j=i+1;j<N;j++)
        {
             double s1=X[i]+t*VX[i]-X[j]-t*VX[j];
             double s2=Y[i]+t*VY[i]-Y[j]-t*VY[j];
             if(s1*s1+s2*s2>maxs)
                maxs=s1*s1+s2*s2;
        }
    return maxs;
}
int main()
{
    int T,cases=1;
    cin>>T;
    while(T--)
    {
        cin>>N;
        for(int i=0;i<N;i++)
            cin>>X[i]>>Y[i]>>VX[i]>>VY[i];
        double left=0,right=100000000,m1,m2;
        for(int i=0;i<100;i++) //枚举的是时间
        {
            m1=left+(right-left)/3;
            m2=right-(right-left)/3;
            if(find(m1)<find(m2))
                right=m2;
            else
                left=m1;
        }
        cout<<"Case #"<<cases++<<": ";
        cout<<setiosflags(ios::fixed)<<setprecision(2);
        cout<<left<<" "<<sqrt(find(left))<<endl;
    }
}
posted on 2015-05-07 15:42  星斗万千  阅读(117)  评论(0编辑  收藏  举报