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

Why WA on #9
Posted by MultiThread 6 Oct 2006 08:55
I got WA on test#9. Could somebody kindly give me some tests? Thanks a lot. :-)
Re: Why WA on #9
Posted by Uran 6 Apr 2007 18:38
I have same thing too.
Re: Why WA on #9
Posted by Iskren Ivov Chernev 7 Oct 2007 20:13
I had WA#9 too. I reviewed my code and tuned thing for precision. Then I got AC.
What can you do for precision:
  -when possible use square of distance (avoid sqrt ())
  --when calculation cos(x) == A^2 + B^2 - C^2 / 2 * A * B you can do something like sqrt (4 * A ^ 2 * B ^ 2) and therefore minimize the number of calls to sqrt
  -calculate sin(x) from cos(x) -- sqrt (1. - cos(x) ^ 2) -- sqrt is better than acos/asin.
  -check for (un)equality using epsilon (mine is 1e-7).
  -call asin/acos after the check (if (a > 1) a = 1; if (a < -1) a = -1)
  -optimize the amount of calculation as much as possible at any step. Avoid calling (sqrt (x)) ^ 2
  -GOOD LUCK

P.S. After additional testing I realized that the 2 most important things are (my problem passed only with this modifications)
-- check if the circle interferes with AB using cos theorem:
if (AC ^ 2 + EPS > AB ^ 2 + BC ^ 2
  ||  BC ^ 2 + EPS > AB ^ 2 + AC ^ 2)
--use sqrt (4 * A ^ 2 * B ^ 2) when calculating a cos of an angle in a triangle using the square of the lengths of its edges.
--calculate sin(x) given cos(x) (without acos) -- sqrt (1 - cos (x) ^ 2)

Edited by author 07.10.2007 20:28
Re: Why WA on #9
Posted by Sean38 22 Dec 2007 21:36
In fact,in #9,A and B are(is?)the same point(s).

Sorry for my poor English.
Re: Why WA on #9
Posted by Dmitry "Logam" Kobelev [TSOGU] 28 Aug 2008 15:59
Yes, they are the same. It's only one place where you need epsilon. All the rest computations could be done with EPS = 0.