需要特判一下n=1的时候
精度调太低会超时
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 310
#define LL long long
#define INF 1e8
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
double vx,vy;
}p[N],pp[N];
int n;
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double calc(double tt)
{
int i,j;
for(i = ; i <= n; i++)
{
pp[i].x=p[i].x+tt*p[i].vx;
pp[i].y=p[i].y+tt*p[i].vy;
}
double ans = 0.0;
for(i = ; i <= n; i++)
{
for(j = ; j <= n ;j++)
ans = max(ans,dis(pp[i],pp[j]));
}
return ans;
}
void solve(int k)
{
double M,RM;
double L = 0.0;
double R = INF;
while (L + eps < R)
{
M = (L + R) / ;
RM = (M + R) / ;
double s1 = calc(M);
double s2 = calc(RM);
if ( s1 < s2 ) R = RM;
else L = M;
}
printf("Case #%d: ",k);
printf("%.2f %.2f\n",R,calc(R));
}
int main()
{
int t,i;
int kk = ;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i <= n ;i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy);
if(n==)
{
printf("0.00 0.00\n");
continue;
}
solve(++kk);
}
return ;
}