have you consider the case when the velocity is 0? that would mean a
division by zero in the step of finding the unit velocity vector.

On Thu, Sep 17, 2009 at 7:03 AM, eSKay <[email protected]> wrote:

>
> what I have done here:
>
> a) i have calculated the dot product of the direction vectors of the
> centre of mass from origin and the velocity vector. this gives me the
> length of projection of the former on the latter - A
> b) i already know the distance of centre of mass from the origin - B
> c) so sqrt(B^2-A^2) gives me the distance of the centre of mass from
> the origin at its minimum value
>
> But I am getting the answer wrong for half of the cases using this
> approach.
>
> I also tried the differentiation method and the output is correct from
> that algorithm. I just wanted to know what could possibly go wrong
> with my code above.
>
>
> On Sep 16, 11:00 pm, Seedrick <[email protected]> wrote:
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to