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 1075. Thread in a Space

Help! WA!
Posted by Marko Tintor (marko@pkj.co.yu) 30 Jun 2002 19:15
#include <fstream.h>
#include <math.h>
ifstream fin("thread.dat");
//#define fin cin
const double M_PI = 3.1415926535897932384626433832795;

class Vec3D
{
public:
    double x,y,z;
    Vec3D() {};
    Vec3D(double X,double Y,double Z): x(X), y(Y), z(Z) {}
    Vec3D operator-(const Vec3D&a){return Vec3D(x-a.x,y-a.y,z-a.z);}
    double operator*(const Vec3D&a){return x*a.x+y*a.y+z*a.z;}
    void operator/=(double a){x/=a;y/=a;z/=a;}
    double module(){return sqrt(x*x+y*y+z*z);}
};

inline double sqr(double x) {return x*x;}
double distance(Vec3D &a, Vec3D &b)
{return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z));}

void main()
{
    Vec3D a,b,c; double r;
    fin >> a.x >> a.y >> a.z;
    fin >> b.x >> b.y >> b.z;
    fin >> c.x >> c.y >> c.z;
    fin >> r;

    double da=distance(a,c), ta=sqrt(da*da-r*r);
    double db=distance(b,c), tb=sqrt(db*db-r*r);

    double alfa=asin(r/da);
    double beta=asin(r/db);
      /// alfa is angle between AC and tangent

    Vec3D ax=a-c, bx=b-c;
    ax/=ax.module(); bx/=bx.module();
    double gama=acos(ax*bx);
      // gama is angle ACB
    double delta=gama+alfa+beta-M_PI;

    cout.precision(2);
    cout << (delta<0 ? distance(a,b) : delta*r+ta+tb) << endl;
}
Re: Help! WA!
Posted by A. Mironenko 28 Feb 2003 20:19
You should have a couple more "if"'s in your program