Someone please tell me what is the problem in my code
#define sq(a) ((a)*(a))
#define ERR 1e-7
int main() {
freopen("B-small-attempt11.in","r",stdin);
freopen("B-small-attempt11.out","w",stdout);
int tc,i,j,k,n,a,b,c,va,vb,vc;
double u[3],ap,dot,dmin,tmin,mod;
cin >> tc;
for(i=0;i<tc;i++) {
cin >> n;
vector<double> p(3,0.0);
vector<double> v(3,0.0);
for(j=0;j<n;j++) {
cin >> a >> b >> c >> va >> vb >> vc;
p[0]+=a;
p[1]+=b;
p[2]+=c;
v[0]+=va;
v[1]+=vb;
v[2]+=vc;
}
p[0]=p[0]/n;
p[1]=p[1]/n;
p[2]=p[2]/n;
v[0]=v[0]/n;
v[1]=v[1]/n;
v[2]=v[2]/n;
mod = sqrt ( sq(v[0])+sq(v[1])+sq(v[2]) );
if(mod < ERR )
{
mod=0.0;
dmin=sqrt (sq(p[0])+sq(p[1])+sq(p[2]));
if(dmin < ERR)
dmin =0.0 ;
printf("Case #%d: %.8lf %.8lf\n",i+1,dmin,mod);
continue;
}
u[0]=v[0]/mod;
u[1]=v[1]/mod;
u[2]=v[2]/mod;
ap=sq(p[0])+sq(p[1])+sq(p[2]);
dot=p[0]*u[0]+p[1]*u[1]+p[2]*u[2];
if(fabs(dot) < ERR)
{
dmin = sqrt(ap);
tmin=0.0;
}
else
{
dmin= ap-sq(dot);
dmin = sqrt(dmin);
tmin = (fabs(dot))/mod;
}
printf("Case #%d: %.8lf %.8lf\n",i+1,dmin,tmin);
}
return 0;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---