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

Help! I cant get AC! what's wrong with my code????
Posted by abc 28 Jan 2003 06:22
/* 1093 */

#include<stdio.h>
#include<iostream.h>
#include<math.h>

void main(){
    long double cx,cy,cz,nx,ny,nz,r;
    long double sx,sy,sz,vx,vy,vz;
    long double a,b,c,d,x,t1,t2,t,mx,my,mz;
    char hit;

    cin >>cx >> cy >> cz >>nx >>ny >>nz >>r >>sx >>sy >>sz >>vx
>>vy >>vz;

    a = nz * 5;
    b = nx * vx + ny * vy + nz * vz;
    c = nx * (cx - sx) + ny * (cy - sy) + nz * (cz - sz);
    /* at^2-bt+c=0 */

    d = b * b - 4 * a * c;
    hit = 0;

    if(d >=0 ){
        d = sqrtl(d);
        t1 = (b + d)/(a + a);
        t2 = (b - d)/(a + a);

        if( t1 >= 0){
            t = t1;
            mx = sx + vx * t;
            my = sy + vy * t;
            mz = sz + vz * t - 5 * t * t;
            x = (mx-cx)*(mx-cx) + (my-cy)*(my-cy) +
(mz-cz)*(mz-cz);
            if(x < r * r) hit = 1;
        }
        if(t2 >= 0){
            t = t2;
            mx = sx + vx * t;
            my = sy + vy * t;
            mz = sz + vz * t - 5 * t * t;
            x = (mx-cx)*(mx-cx) + (my-cy)*(my-cy) +
(mz-cz)*(mz-cz);
            if(x < r * r) hit = 1;
        }
    }
    if(hit) printf("HIT\n");
    else printf("MISSED\n");
}
Re: Help! I cant get AC! what's wrong with my code????
Posted by Kolio 7 May 2003 19:55
Maybe there is a problem with the exactness.

try comareing with
x < y - 1e-8
instead of
x < y
and
x > y + 1e-8
instead of
x > y