|
|
back to boardWA7, what wrong? 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? 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? 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? Use the law of sines instead of cosines. |
|
|