Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 710 Accepted Submission(s): 290
#include<iostream> #include<cstring> #include<string> #include<cmath> #include<cstdio> using namespace std; double eps=1e-6; int n; //点的个数 struct mq { double x; double y; double vx; double vy; }; mq node[305]; double dis(mq a,mq b,double t) { return sqrt((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 cal(double t) { int i,j; double ans=0; for(i=0;i<n;i++) for(j=i+1;j<n;j++) ans=max(ans,dis(node[i],node[j],t)); return ans; } int main() { int tes,i; scanf("%d",&tes); int cas=0; while(tes--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf%lf%lf",&node[i].x,&node[i].y,&node[i].vx,&node[i].vy); double left,right,mid,mimid; left=0,right=10000000; while(right-left>eps) { mid=(left+right)/2.0,mimid=(right+mid)/2.0; if(cal(mid)<cal(mimid)) right=mimid; else left=mid; } printf("Case #%d: %.2f %.2f\n",++cas,mid,cal(mid)); } return 0; } /* 45 2 0 0 1 0 2 0 -1 0 2 -1000000 0 1 0 1000000 0 -1 0 2 1000000 0 0 0 -1000000 0 0 0 2 1000000 1000000 0 0 -1000000 -1000000 0 0 3 2 2 0 0 1 1 0 0 4 4 0 0 */
#include<iostream> #include<cstring> #include<string> #include<cmath> #include<cstdio> using namespace std; double eps=1e-6; int n; struct mq { double x; double y; double vx; double vy; }; mq node[305]; double ps,pt; void cal() { double fent=10000000; double l=0,r=fent,t; int i,j; while(fent>eps) { for(t=l; t<=r; t+=fent) { double tmp=0; for(i=0; i<n; i++) for(j=i+1; j<n; j++) { double a,b,c,d; a=node[i].x+node[i].vx*t; b=node[i].y+node[i].vy*t; c=node[j].x+node[j].vx*t; d=node[j].y+node[j].vy*t; double sq=sqrt((a-c)*(a-c)+(b-d)*(b-d)); if(sq>tmp) tmp=sq; } if(tmp<ps) { ps=tmp; pt=t; } } if(pt<fent) { l=0,r=fent; } else { l=pt-fent,r=pt+fent; } fent=fent/10.0; } } int main() { int tes,i; scanf("%d",&tes); int cas=0; while(tes--) { scanf("%d",&n); for(i=0; i<n; i++) scanf("%lf%lf%lf%lf",&node[i].x,&node[i].y,&node[i].vx,&node[i].vy); ps=100000000.0; cal(); printf("Case #%d: %.2f %.2f\n",++cas,pt,ps); } return 0; } /* 45 2 0 0 1 0 2 0 -1 0 2 -1000000 0 1 0 1000000 0 -1 0 2 1000000 0 0 0 -1000000 0 0 0 2 1000000 1000000 0 0 -1000000 -1000000 0 0 3 2 2 0 0 1 1 0 0 4 4 0 0 */