|
|
вернуться в форумWhy WA on #9 I got WA on test#9. Could somebody kindly give me some tests? Thanks a lot. :-) Re: Why WA on #9 Послано Uran 6 апр 2007 18:38 I have same thing too. Re: Why WA on #9 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 Послано Sean38 22 дек 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 Yes, they are the same. It's only one place where you need epsilon. All the rest computations could be done with EPS = 0. |
|
|