三分时间。。。。算是个水题了,这是做比赛的时候有点犹豫了
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define maxn 305
using namespace std;
const int inf=0x7ffffff;
const double PI=acos(-1.0);
const double eps=1e-8;
const double e=2.7182818284590452354;
struct point
{
double x,y;
double vx,vy;
point() {}
point(double x,double y,double vx,double vy): x(x),y(y),vx(vx),vy(vy) {}
}p[maxn];
int n;
double getdist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double getmaxdist(double t)
{
point pp[maxn];
for(int i=0;i<n;i++)
{
pp[i].x=p[i].x+p[i].vx*t;
pp[i].y=p[i].y+p[i].vy*t;
}
double ret=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
ret=max(ret,getdist(pp[i],pp[j]));
return ret;
}
int main()
{
int t;
int cas=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy);
double l,r,m1,m2;
l=0;
r=1e8;
while(l+eps<r)
{
m1=(2*l+r)/3.0;
m2=(l+2*r)/3.0;
if(getmaxdist(m1)<getmaxdist(m2))
r=m2;
else l=m1;
}
printf("Case #%d: ",cas++);
printf("%.2lf %.2lf\n",l,getmaxdist(l));
}
return 0;
}