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 1729. Dead Man's Chest

WA7, what wrong?
Posted by Dmitriy S. Hodyrev 17 Oct 2009 19:01
Many times my code was reviewed and rewatched, but still WA7.
Could anybody help? What wrong with code? May be this algorithm gives not the optimal path?

int main()
{
    double r, a;
    std::cin >> r >> a;
    // first, walk to the edge of the island
    double s = r;
    // total angle of undiscovered edge
    const double a_left = 360.0 - 2.0*a;
    // hops count on 2*a "arc" line
    const int full_hops = (int)(a_left / (2.0*a));
    s += range(r, to_rad(2.0*a)) * full_hops;
    // remaining angle to hop
    double a_rem = a_left - full_hops * (2.0 * a);
    s += range(r, to_rad(a_rem));
    std::cout << std::fixed << std::setprecision(12) << s << std::endl;
}
Re: WA7, what wrong?
Posted by melkiy 17 Oct 2009 23:50
Your algorithm allows me to AC.
Maybe problem in calculations, in "to_rad" or "range"...

I wrote to_rad and range to compile your code, and compared my code with yours: all output is identical. So, maybe you've mistook in one of these functions.

Edited by author 18.10.2009 00:00
Re: WA7, what wrong?
Posted by Dmitriy S. Hodyrev 18 Oct 2009 01:06
Thank you a lot for a great advice!

Problem was eliminated after rewriting range() function:
Old: used cosinus theorem
New: using sinus to radius multiplication

AC!
Re: WA7, what wrong?
Posted by melkiy 18 Oct 2009 01:54
Dmitriy S. Hodyrev!

You solved 1726. If you read this, help me, please.
My e-mail in my profile.

Moders, sorry for the message concerning not this problem. But did you think about a functionality of allowing users to send private messages to the other users' e-mails through a web-form?
Re: WA7, what wrong?
Posted by SuperLight 18 Oct 2009 10:07
Re: WA7, what wrong?
Posted by Alexander Georgiev 23 Oct 2009 19:53
I had the same problem: Since the cosine can be quite close to zero its square root is not calculated properly. So I also didn't use cosine theorem but calculated the length of the chords with simpler geometry:

long double x = radius * cos(angle);
long double y = radius * sin(angle);
long double ans = sqrt((x - radius) * (x - radius) + y * y);

Here the square root is done over the distance, not over the cosine, which, as it seems, solved the problem.
Re: WA7, what wrong?
Posted by Kolobov_Oleg 10 Jan 2010 00:14
Use the law of sines instead of cosines.
Re:
Posted by SuperLight 10 Jan 2010 10:10