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.
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 thpoint, 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).
2 2 0 0 1 0 2 0 -1 0 2 0 0 1 0 2 1 -1 0
Case #1: 1.00 0.00Case #2: 1.00 1.00
思路:三分
ac代码:
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<sstream> #include<queue> #include<map> #include<set> #include<cmath> #define LL long long #define INF 0x3f3f3f3f using namespace std; const int maxn = 305; int T; int n; struct node { double x,y; double vx,vy; }N[maxn]; double dis(node a,node b,double t) { return ((a.x+a.vx*t)-(b.x+b.vx*t))*((a.x+a.vx*t)-(b.x+b.vx*t))+((a.y+a.vy*t)-(b.y+b.vy*t))*((a.y+a.vy*t)-(b.y+b.vy*t)); } double check(double t) { double ret = 0; for(int i = 0;i<n;i++){ for(int j = i+1;j<n;j++){ ret = max(dis(N[i],N[j],t),ret); } } return sqrt(ret); } int main() { scanf("%d",&T); int kase = 1; while(T--){ scanf("%d",&n); for(int i = 0;i<n;i++){ scanf("%lf%lf%lf%lf",&N[i].x,&N[i].y,&N[i].vx,&N[i].vy); } double mid; double rmid; double l = 0; double r = 1e9; for(int i = 0;i<=100;i++){ mid = (l+r)/2; rmid = (mid+r)/2; if(check(mid)<check(rmid)){ r = rmid; } else{ l = mid; } } double anst; double ansd; if(check(l)<check(r)){ anst = l; ansd = check(l); } else{ anst = r; ansd = check(r); } printf("Case #%d: %.2lf %.2lf\n",kase++,anst,ansd); } }