ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1075. Нитка в пространстве

Could someone help me?
Послано Krzysztof Kapuscik 1 сен 2001 15:29
Below is my code for it. Could someone tell me what's wrong?

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

double ax,ay,az;
double bx,by,bz;
double cx,cy,cz,r;
double dx,dy;

double gx1,gy1,gx2,gy2;
double fx,fy,gx,gy;
double alfa;

double ab,ac,bc;

double VectLen(double x,double y,double z)
{    return sqrt(x*x+y*y+z*z);    }
double VectLen(double x,double y)
{    return sqrt(x*x+y*y);    }
double Area(double a,double b,double c)
{    double p = (a+b+c)/2;
   return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main()
{
    cin >> ax >> ay >> az;
   cin >> bx >> by >> bz;
   cin >> cx >> cy >> cz >> r;
   if (ax==bx && ay==by && az==bz)
   {    cout << "0.00" << endl;    return 0;    }

   ab = VectLen(ax-bx,ay-by,az-bz);
   ac = VectLen(ax-cx,ay-cy,az-cz);
   bc = VectLen(bx-cx,by-cy,bz-cz);

//   cout << "AB = " << ab << " AC = " << ac << " BC = " <<
bc << endl;

   if (Area(ab,ac,bc)/ab>=r)
   {    printf("%.2lf\n",ab);    return 0;    }

//   cout << "TRIANGLE AREA = " << Area(ab,ac,bc) << endl;
//    cout << "DISTANCE CD = " << (Area(ab,ac,bc)/ab) <<
endl;

   ax = -ac;    ay = 0;
   bx = (ab*ab-ac*ac-bc*bc)/(2*ac);        by = sqrt
(bc*bc-bx*bx);
   cx = 0;        cy = 0;
//   cout << "A = (" << ax << ',' << ay << ')' << endl;
//   cout << "B = (" << bx << ',' << by << ')' << endl;
//   cout << "C = (" << cx << ',' << cy << ')' << endl;

   dy = (ax*by*(ax-bx)) / ((bx-ax)*(bx-ax) - by*(ay-by));
   dx = -((ay-by)/(ax-bx)) * dy;
//   cout << "D = (" << dx << ',' << dy << ')' << endl;

   if (VectLen(ax-dx,ay-dy)+VectLen(bx-dx,by-dy) > ab)
   {    printf("%.2lf\n",ab);    return 0;    }
//   cout << (VectLen(ax-dx,ay-dy)+VectLen(bx-dx,by-dy))
<< ' ' << ab << endl;

    fx = r*r / ax;        fy = sqrt(r*r - fx*fx);
//   cout << "F = (" << fx << ',' << fy << ')' << endl;

   double del;
   if (bx!=0)
   {
       del = (-2*r*r*by)*(-2*r*r*by)-4*(by*by+bx*bx)*
(r*r*(r*r-bx*bx));
       if (del < 0)
           abort();
    //   cout << "DELTA = " << del << endl;
       gy1 = (2*r*r*by + sqrt(del)) / (2*(by*by+bx*bx));
      gy2 = (2*r*r*by - sqrt(del)) / (2*(by*by+bx*bx));
       gx1 = (r*r-by*gy1) / bx;
       gx2 = (r*r-by*gy2) / bx;
      if (VectLen(fx-gx1,fy-gy1) < VectLen(fx-gx2,fy-gy2))
      {    gx = gx1;    gy = gy1;    }
      else
      {    gx = gx2;    gy = gy2;    }
   }
   else
   {
       gy = r*r / by;
      gx = - sqrt(r*r-gy*gy);
   }
    //   cout << "G = (" << gx << ',' << gy << ')' <<
endl;


   alfa = acos((fx*gx + fy*gy) / (r*r));
   if (alfa < 0)
       alfa *= -1;
//   cout << "ALFA = " << alfa << endl;

//   cout << setprecision(2) << double(VectLen(ax-fx,ay-fy)
+VectLen(bx-gx,by-gy)+alfa*r) << endl;
   printf("%.2lf\n", (VectLen(ax-fx,ay-fy)+VectLen(bx-gx,by-
gy)+alfa*r));

    return 0;
}

Thanks.
SAV
Comment your code before :^)
Послано A. Mironenko 14 сен 2001 18:47
> Below is my code for it. Could someone tell me what's
wrong?

Could you say after two weeks what your program is doing in
particular line?

You should better erase commented lines and
add new _meaningfull_ comments to key lines

And only after such preparing you may ask such questions :)