|
|
back to boardThis problem seems to be quite easy and i almost sure in the correctness of my program....BUT WA!!!!!!SO HELPHELPHELPHELP This is my code: #include<iostream.h> #include<math.h> //ifstream fin("input.txt"); long double cx,cy,cz,nx,ny,nz,r,sx,sy,sz,vx,vy,vz; int main(){ cin >>cx >> cy >> cz >>nx >>ny >>nz >>r >>sx >>sy >>sz >>vx >>vy >>vz; cx-=sx; cy-=sy; cz-=sz; long double V=(nx*vx+ny*vy+nz*vz)/sqrtl(nx*nx+ny*ny+nz*nz); long double G=-(10*nz)/sqrtl(nx*nx+ny*ny+nz*nz); long double L=(cx*nx+cy*ny+cz*nz)/sqrtl(nx*nx+ny*ny+nz*nz); if(V*V+2*L*G<0) { cout << "MISSED\n"; return 0; } long double t=(-V+sqrtl(V*V+2*L*G))/G; if(t>=0) { long double xp=vx*t-cx; long double yp=-cy+vy*t; long double zp=-cz+vz*t-5*t*t; if((xp)*(xp)+(yp)*(yp)+(zp)*(zp)<r*r) { cout << "HIT\n"; return 0; } } t=(-V-sqrtl(V*V+2*L*G))/G; if(t>=0) { long double xp=-cx+vx*t; long double yp=-cy+vy*t; long double zp=-cz+vz*t-5*t*t; if((xp)*(xp)+(yp)*(yp)+(zp)*(zp)<r*r) { cout << "HIT\n"; return 0; } } cout << "MISSED\n"; return 0; } Oh there really was small bug in my program now i get ac > This is my code: > #include<iostream.h> > #include<math.h> > //ifstream fin("input.txt"); > long double cx,cy,cz,nx,ny,nz,r,sx,sy,sz,vx,vy,vz; > int main(){ > cin >>cx >> cy >> cz >>nx >>ny >>nz >>r >>sx >>sy >>sz >>vx > >>vy >>vz; > cx-=sx; > cy-=sy; > cz-=sz; > long double V=(nx*vx+ny*vy+nz*vz)/sqrtl(nx*nx+ny*ny+nz*nz); > long double G=-(10*nz)/sqrtl(nx*nx+ny*ny+nz*nz); > long double L=(cx*nx+cy*ny+cz*nz)/sqrtl(nx*nx+ny*ny+nz*nz); > if(V*V+2*L*G<0) > { > cout << "MISSED\n"; > return 0; > } > long double t=(-V+sqrtl(V*V+2*L*G))/G; > if(t>=0) > { > long double xp=vx*t-cx; > long double yp=-cy+vy*t; > long double zp=-cz+vz*t-5*t*t; > if((xp)*(xp)+(yp)*(yp)+(zp)*(zp)<r*r) > { > cout << "HIT\n"; > return 0; > } > } > t=(-V-sqrtl(V*V+2*L*G))/G; > if(t>=0) > { > long double xp=-cx+vx*t; > long double yp=-cy+vy*t; > long double zp=-cz+vz*t-5*t*t; > if((xp)*(xp)+(yp)*(yp)+(zp)*(zp)<r*r) > { > cout << "HIT\n"; > return 0; > } > } > cout << "MISSED\n"; > return 0; > } > > > what's bug in this program?? Posted by hawking 21 Aug 2002 16:29 Re: what's bug in this program?? |
|
|