B - The Moving Points

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

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

For next  N N lines, each come with four integers  Xi Xi Yi Yi VXi VXi and  VYi VYi ( 106Xi −106≤Xi Yi106 Yi≤106 102VXi −102≤VXi VYi102 VYi≤102), ( Xi Xi Yi Yi) is the position of the  ith ith point, and ( VXi VXi VYi VYi) is its speed with direction. 
That is to say, after  1 1 second, this point will move to ( Xi+VXi Xi+VXi Yi+VYi Yi+VYi).

Output

For test case  X X, output Case #X: first, then output two numbers, rounded to  0.01 0.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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值