给n个点,和每个点的单位时间移动向量,求一个时刻,使得n个点中,两两之间距离的最大值最小。
最X值最Y这种形式第一反应都是二分三分。注意到对于两个点,距离对时间t的函数是一个下凸函数,而对F(t)=max(f1(t),f2(t)....fn(t)),若f1..fn都是下凸函数,那么F也是一个下凸函数,所以直接三分时间t,n^2求一下点间距离的最大值就好了。
/*=============================================================================
# Author:Erich
# FileName:
=============================================================================*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#define lson id<<1,l,m
#define rson id<<1|1,m+1,r
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=1ll<<60;
const double PI=acos(-1.0);
int n,m;
const double eps=1e-12;
struct Point
{
double x,y;
Point()
{
}
Point(double a,double b)
{
x=a; y=b;
}
void read()
{
scanf("%lf%lf",&x,&y);
}
};
typedef Point Vector;
struct node
{
Point p;
Vector v;
Point pos(double t)
{
return Point(p.x+v.x*t,p.y+v.y*t);
}
}a[500];
double dis(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double F(double t)
{
double mx=-1;
Point p1,p2;
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
{
p1=a[i].pos(t);
p2=a[j].pos(t);
mx=max(mx,dis(p1,p2));
}
return mx;
}
int main()
{
//freopen("in.txt","r",stdin);
int tt;
scanf("%d",&tt);
int cnt=0;
while(tt--)
{
scanf("%d",&n);
for (int i=0; i<n; i++)
{
a[i].p.read();
a[i].v.read();
}
double L=0,R=1e8+1;
for (int i=0; i<100; i++)
{
double m1=L+(R-L)/3;
double m2=R-(R-L)/3;
if (F(m1)<F(m2)) R=m2;else L=m1;
}
printf("Case #%d: %.2lf %.2lf\n",++cnt,L,sqrt(F(L)));
}
return 0;
}