B - The Moving Points

来源:互联网 发布:mac怎么登陆两个微信 编辑:程序博客网 时间:2024/06/07 15:56

There are NN 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 first line has a number TT (T10T≤10) , indicating the number of test cases.

For each test case, first line has a single number NN (N300N≤300), which is the number of points.

For next NN lines, each come with four integers XiXiYiYiVXiVXi and VYiVYi (106Xi−106≤XiYi106Yi≤106102VXi−102≤VXiVYi102VYi≤102), (XiXiYiYi) is the position of the ithith point, and (VXiVXiVYiVYi) is its speed with direction. 
That is to say, after 11 second, this point will move to (Xi+VXiXi+VXiYi+VYiYi+VYi).

Output

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

Sample Input



0 0 1 0 
2 0 -1 0 

0 0 1 0 
2 1 -1 0

Sample Output

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));
    }
}


0 0
原创粉丝点击