HDOJ 4717 The Moving Points

The Moving Points

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 878    Accepted Submission(s): 353

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 Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
 
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
 
Source
 
Recommend
zhuyuanchen520
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; const double eps=1e-;
const double INF=0x3f3f3f3f; struct point
{
double x,y;
double vx,vy;
point() {}
point(double a,double b,double c,double d):x(a),y(b),vx(c),vy(d){}
}P[]; double getP2Pdist(point a,point b,double t)
{
double x1=a.x+t*a.vx,y1=a.y+t*a.vy;
double x2=b.x+t*b.vx,y2=b.y+t*b.vy;
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} double LMdist(int n,double t)
{
double ans=-INF;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
ans=max(ans,getP2Pdist(P[i],P[j],t));
}
}
return ans;
} int main()
{
int t,n,cas=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
double a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
P[i]=point(a,b,c,d);
}
double low=,high=,midlow,midhigh;
int cnt=;
while(cnt<=)
{
cnt++;
midlow=(low*+high)/.,midhigh=(low+high*)/.;
double distlow=LMdist(n,midlow);
double disthigh=LMdist(n,midhigh);
if(distlow>disthigh) low=midlow;
else high=midhigh;
}
double anstime=low;
double ansdist=LMdist(n,low);
printf("Case #%d: %.2lf %.2lf\n",cas++,anstime,ansdist);
}
return ;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
上一篇:Moving Tables(贪心或Dp POJ1083)


下一篇:BizTalk动手实验(十七)ODBC适配器使用