Puzzled by test #5
Posted by 
deserts 12 Jul 2004 17:50
I'm sure my source code is perfect. But it never passed test #5. Can anyone help me?
 
#include <stdio.h>
#include <math.h>
int main()
{
        double  cx,cy,cz,nx,ny,nz,r,sx,sy,sz,vx,vy,vz,t;
        double  x,y,z;
        double  a,b,c;
        int     hit;
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&cx,&cy,&cz,&nx,&ny,&nz,&r,&sx,&sy,&sz,&vx,&vy,&vz);
        b=nx*vx+ny*vy+nz*vz;
        c=nx*(sx-cx)+ny*(sy-cy)+nz*(sz-cz);
        a=-5*nz;
        if(b*b-4*a*c<-1e-8)
                printf("MISSED\n");
        else if((b+sqrt(b*b-4*a*c))/nz<-1e-8 && (b-sqrt(b*b-4*a*c))/nz<-1e-8)
                printf("MISSED\n");
        else
        {
                hit=0;
                t=(b-sqrt(b*b-4*a*c))/(10*nz);
                if(t>1e-8)
                {
                        x=sx+vx*t;
                        y=sy+vy*t;
                        z=sz+vz*t-5*t*t;
                        if(r-sqrt(pow(x-cx,2)+pow(y-cy,2)+pow(z-cz,2))>1e-8)
                                ++hit;
                }
                t=(b+sqrt(b*b-4*a*c))/(10*nz);
                if(t>1e-8)
                {
                        x=sx+vx*t;
                        y=sy+vy*t;
                        z=sz+vz*t-5*t*t;
                        if(r-sqrt(pow(x-cx,2)+pow(y-cy,2)+pow(z-cz,2))>1e-8)
                                ++hit;
                }
                if(hit)
                        printf("HIT\n");
                else
                        printf("MISSED\n");
        }
        return 0;
}