Problem Description
There are 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 rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).
Output
For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
Sample Input
2
2
0 0 1 0
2 0 -1 0
2
0 0 1 0
2 1 -1 0
Sample Output
Case #1: 1.00 0.00
Case #2: 1.00 1.00
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <stdio.h> #include <math.h> int N; struct Point { double x,y; double vx,vy; }p[305],a[305]; double Length(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double F(double mid) { for(int j=0; j<N; j++) { p[j].x = a[j].x+p[j].vx*mid; p[j].y = a[j].y+p[j].vy*mid; } double ans=-1,temp; for(int i=0; i<N-1; i++) { for(int j=i+1; j<N; j++) { temp=Length(p[i],p[j]); if(ans<temp) ans=temp; } } return ans; } int main() { int T,i,k,L,cnt=0; scanf("%d",&T); while(T--) { scanf("%d",&N); for(i=0; i<N; i++) { scanf("%lf %lf %lf %lf",&p[i].x,&p[i].y,&p[i].vx,&p[i].vy); a[i].x=p[i].x,a[i].y=p[i].y; a[i].vx=p[i].vx,a[i].vy=p[i].vy; } k=100; double l=0,r=1000.0,mid1,mid2; while(k--) { mid1 = l +(r-l)/3; mid2 = r-(r-l)/3; if(F(mid1)<F(mid2)) r=mid2; else l=mid1; } printf("Case #%d: %.2lf %.2lf\n",++cnt,l,F(l)); } return 0; }