ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1093. Darts

Why WA #3 ?????????
Posted by REM 23 Jun 2005 02:40
#include <stdio.h>
#include <fstream.h>
#include <math.h>

double Cx,Cy,Cz,Nx,Ny,Nz,R,Sx,Sy,Sz,Vx,Vy,Vz;
double A,B,C,D;
double l,m,n;
double x,y,z;
double vec,dist;
double a,b,c,dd,t,t1,t2;

double distance(double x,double y,double z,double x1,double y1,double z1) {
 double rez;
 rez=sqrtl(pow(x-x1,2)+pow(y-y1,2)+pow(z-z1,2));
 return rez;
}

int main()   {
 #ifndef ONLINE_JUDGE
    freopen("1093.in","r",stdin);
    freopen("1093.out","w",stdout);
 #endif
 scanf("%lf %lf %lf",&Cx,&Cy,&Cz);
 scanf("%lf %lf %lf",&Nx,&Ny,&Nz);
 scanf("%lf",&R);
 scanf("%lf %lf %lf",&Sx,&Sy,&Sz);
 scanf("%lf %lf %lf",&Vx,&Vy,&Vz);
 //---------------
 A=Nx;B=Ny;C=Nz;
 D=-(A*Cx+B*Cy+C*Cz);
 //-----------------
 a=-5*C;
 b=A*Vx+B*Vy+C*Vz;
 c=A*Sx+B*Sy+C*Sz+D;
 if (fabs(a)<0.0000001) {
  if (fabs(b)<0.0000001) {printf("MISSED"); return 0;}
  t=-c/b;
  x=Sx+Vx*t;
  y=Sx+Vy*t;
  z=Sx+Vz*t-5*t*t;
    if (distance(x,y,z,Cx,Cy,Cz)<R-0.000001) {printf("HIT"); return 0;}
    else {printf("MISSED"); return 0;}
 }

 dd=b*b-4*a*c;
 if (dd<0) {printf("MISSED");return 0;}

 dd=sqrtl(dd);
 t1=(-b+dd)/(2*a);
 t2=(-b-dd)/(2*a);
 if ((t1<0) && (t2<0)) {printf("MISSED");return 0;}

 //printf("dd=%lf\n",dd);
 //printf("t=%lf\n",t);
 if (t1>=0) {
    x=Sx+Vx*t1;
    y=Sx+Vy*t1;
    z=Sx+Vz*t1-5*t1*t1;
    if (distance(x,y,z,Cx,Cy,Cz)<(R-0.000001)) {printf("HIT"); return 0;}
  }

 if (t2>=0) {
    x=Sx+Vx*t2;
    y=Sx+Vy*t2;
    z=Sx+Vz*t2-5*t2*t2;
    if (distance(x,y,z,Cx,Cy,Cz)<(R-0.000001)) {printf("HIT"); return 0;}
  }

 printf("MISSED");
 return 0;
 #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
 #endif
}
Maybe anyone knows what the test #3?
Posted by REM 23 Jun 2005 18:35
Maybe anyone knows what the test #3?
Because I cannot find the mistake in my code.

Edited by author 23.06.2005 18:36
Re: Why WA #3 ?????????
Posted by Ich 23 Jun 2005 18:53
When you calculate x,y,z u must use Sx,Sy,Sz but you use only Sx