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 1285. Thread in a Hyperspace

What's wrong? Tests' incorect?
Posted by pperm 30 Jul 2007 23:57
Фрагмент кода при проверки лежит ли путь через сферу.
Почему то вещественная проверка проходит, а целочисленная нет. хотя в long long все должно влазить. Извините, что на русском, но писать на английском я совсем не могу)
    int i;
    long long a=0,b=0;
    for (i=0;i<maxd;i++)
    {
        a+=sqr(p2.x[i]-p1.x[i]);
        b+=(p2.x[i]-p1.x[i])*(x[i]-p1.x[i]);
    }
    if (b<0||b>a)
        return false;
//-AC-----------------------------------
    double t=(double)b/a;
    double rr=0;
    for (i=0;i<maxd;i++)
        rr+=sqr((p2.x[i]-p1.x[i])*t+p1.x[i]-x[i]);
    rr=sqrt(rr);
    return rr<r;
//-WA7-----------------------------------
    long long t=0;
    for (i=0;i<maxd;i++)
        t+=sqr((p2.x[i]-p1.x[i])*b+a*p1.x[i]-a*x[i]);
    return r*r*a*a>t;
}
//В задаче 1075 тоже самое только WA на 12 тесте.


Edited by author 31.07.2007 12:53
Re: What's wrong? Tests' incorect?
Posted by Sandro (USU) 31 Jul 2007 17:45
For example,
r=1000, a=8*(1000-(-1000))^2=32000000.
r*r*a*a > MaxLongLongInt.
Re: What's wrong? Tests' incorect?
Posted by pperm 25 Sep 2007 09:00
thank you))

Edited by author 25.09.2007 09:29
Re: What's wrong? Tests' incorect?
Posted by pperm 25 Sep 2007 09:52
Tests correct.
I AC with Long arithmetic.