HDU 4717The Moving Points warmup2 1002题(三分)
发布时间: 2013-09-28 10:01:20 作者: rapoo
HDU 4717The Moving Points warmup2 1002题(三分)
220 0 1 02 0 -1 020 0 1 02 1 -1 0
Case #1: 1.00 0.00Case #2: 1.00 1.00
#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;}/*4520 0 1 02 0 -1 02-1000000 0 1 01000000 0 -1 021000000 0 0 0-1000000 0 0 021000000 1000000 0 0-1000000 -1000000 0 032 2 0 01 1 0 04 4 0 0*/