Re: [gcj] BullsEye Problem - Python Troubleshooting help!
Is it possible to in different time zone On Sun, Apr 28, 2013 at 5:23 PM, Samuel Jawahar wrote: > Is it possible to in different timt zone > > > On Sat, Apr 27, 2013 at 4:52 PM, Joseph DeVincentis wrote: > >> The problem with this is that pow(foo, 0.5) performs a floating point >> calculation which is not accurate to the 18 significant figures required >> for this result. >> >> >> On Sat, Apr 27, 2013 at 6:55 AM, wonjun wrote: >> >>> I used the following logic for the problem - >>> >>> Let k be the required answer. Then, >>> (R+1)^2 - R^2 = 2R + 1 amount of paint to paint the first circle >>> (R+3)^2 - (R+2)^2 = 2R + 5 amount of paint to paint the second circle. >>> ... >>> and so on - we get total k equations. >>> >>> Now, adding the k equations, and putting the RHS <= t we get the >>> following quadratic inequality: >>> >>> 2k^2 + (2R - 1)k - t <= 0. >>> So I managed to get a closed formula for this problem. >>> >>> However, when I ran my code to the test cases given, it solved them all >>> correctly, except for the last one. I double checked my soln; seemed there >>> was nothing at all but a problem in Python (I think.). >>> >>> Substituting k = 49 works, but k = 50 in (*) makes RHS > 0. >>> [Check the following code] >>> >>> >>> def check(k): >>> r,t = 1, 100 >>> if 2*k*k + 2*(r-1)*k - t <= 0: >>> return True >>> return False >>> >>> >>> check(49) >>> True >>> >>> check(50) >>> False >>> >>> >>> r,t = 1, 100 >>> >>> (-(2*r - 1) + pow(pow((2*r - 1), 2) + 4*2*t, 0.5))/4.0 ## Note >>> that this is the closed formula. >>> 50.0 >>> >>> >>> I wonder what's causing such error? Is it because of calculation of big >>> numbers? >>> Anyhow, in seeing this I managed to submit for A small. I changed my >>> code abit using while loop and tweaking alittle and submitted large; but >>> got it wrong in the end. >>> >>> I'm currently using Python 2.7. >>> Any reason why its behaving so weirdly? >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Google Code Jam" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to google-code+unsubscr...@googlegroups.com. >>> To post to this group, send email to google-code@googlegroups.com. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Code Jam" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to google-code+unsubscr...@googlegroups.com. >> To post to this group, send email to google-code@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] BullsEye Problem - Python Troubleshooting help!
Is it possible to in different timt zone On Sat, Apr 27, 2013 at 4:52 PM, Joseph DeVincentis wrote: > The problem with this is that pow(foo, 0.5) performs a floating point > calculation which is not accurate to the 18 significant figures required > for this result. > > > On Sat, Apr 27, 2013 at 6:55 AM, wonjun wrote: > >> I used the following logic for the problem - >> >> Let k be the required answer. Then, >> (R+1)^2 - R^2 = 2R + 1 amount of paint to paint the first circle >> (R+3)^2 - (R+2)^2 = 2R + 5 amount of paint to paint the second circle. >> ... >> and so on - we get total k equations. >> >> Now, adding the k equations, and putting the RHS <= t we get the >> following quadratic inequality: >> >> 2k^2 + (2R - 1)k - t <= 0. >> So I managed to get a closed formula for this problem. >> >> However, when I ran my code to the test cases given, it solved them all >> correctly, except for the last one. I double checked my soln; seemed there >> was nothing at all but a problem in Python (I think.). >> >> Substituting k = 49 works, but k = 50 in (*) makes RHS > 0. >> [Check the following code] >> >> >>> def check(k): >> r,t = 1, 100 >> if 2*k*k + 2*(r-1)*k - t <= 0: >> return True >> return False >> >> >>> check(49) >> True >> >>> check(50) >> False >> >> >>> r,t = 1, 100 >> >>> (-(2*r - 1) + pow(pow((2*r - 1), 2) + 4*2*t, 0.5))/4.0 ## Note >> that this is the closed formula. >> 50.0 >> >> >> I wonder what's causing such error? Is it because of calculation of big >> numbers? >> Anyhow, in seeing this I managed to submit for A small. I changed my code >> abit using while loop and tweaking alittle and submitted large; but got it >> wrong in the end. >> >> I'm currently using Python 2.7. >> Any reason why its behaving so weirdly? >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Code Jam" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to google-code+unsubscr...@googlegroups.com. >> To post to this group, send email to google-code@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] BullsEye Problem - Python Troubleshooting help!
So, this could be the same problem with sqrt() on C++? I took the same approach, found a formula to get the answer directly for the large input and was too stuck on "omg, but my formula is right", revising it over and over to try to see the error... took me almost the entire round :( Em sábado, 27 de abril de 2013 08h22min25s UTC-3, /dev/joe escreveu: > The problem with this is that pow(foo, 0.5) performs a floating point > calculation which is not accurate to the 18 significant figures required for > this result. > > > > > On Sat, Apr 27, 2013 at 6:55 AM, wonjun wrote: > > > I used the following logic for the problem - > > > Let k be the required answer. Then, > (R+1)^2 - R^2 = 2R + 1 amount of paint to paint the first circle > > (R+3)^2 - (R+2)^2 = 2R + 5 amount of paint to paint the second circle. > ... > and so on - we get total k equations. > > > Now, adding the k equations, and putting the RHS <= t we get the following > quadratic inequality: > > > > > 2k^2 + (2R - 1)k - t <= 0. > So I managed to get a closed formula for this problem. > > > However, when I ran my code to the test cases given, it solved them all > correctly, except for the last one. I double checked my soln; seemed there > was nothing at all but a problem in Python (I think.). > > > > > > Substituting k = 49 works, but k = 50 in (*) makes RHS > 0. > [Check the following code] > > > >>> def check(k): > r,t = 1, 100 > > > if 2*k*k + 2*(r-1)*k - t <= 0: > return True > return False > > > > >>> check(49) > True > >>> check(50) > False > > > >>> r,t = 1, 100 > >>> (-(2*r - 1) + pow(pow((2*r - 1), 2) + 4*2*t, 0.5))/4.0 ## Note that > >>> this is the closed formula. > > > 50.0 > > > > > I wonder what's causing such error? Is it because of calculation of big > numbers? > Anyhow, in seeing this I managed to submit for A small. I changed my code > abit using while loop and tweaking alittle and submitted large; but got it > wrong in the end. > > > > > > I'm currently using Python 2.7. > Any reason why its behaving so weirdly? > > > > > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code...@googlegroups.com. > > To post to this group, send email to googl...@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/google-code/-/485Ai8Xz3DsJ. For more options, visit https://groups.google.com/groups/opt_out.
Re: [gcj] BullsEye Problem - Python Troubleshooting help!
The problem with this is that pow(foo, 0.5) performs a floating point calculation which is not accurate to the 18 significant figures required for this result. On Sat, Apr 27, 2013 at 6:55 AM, wonjun wrote: > I used the following logic for the problem - > > Let k be the required answer. Then, > (R+1)^2 - R^2 = 2R + 1 amount of paint to paint the first circle > (R+3)^2 - (R+2)^2 = 2R + 5 amount of paint to paint the second circle. > ... > and so on - we get total k equations. > > Now, adding the k equations, and putting the RHS <= t we get the following > quadratic inequality: > > 2k^2 + (2R - 1)k - t <= 0. > So I managed to get a closed formula for this problem. > > However, when I ran my code to the test cases given, it solved them all > correctly, except for the last one. I double checked my soln; seemed there > was nothing at all but a problem in Python (I think.). > > Substituting k = 49 works, but k = 50 in (*) makes RHS > 0. > [Check the following code] > > >>> def check(k): > r,t = 1, 100 > if 2*k*k + 2*(r-1)*k - t <= 0: > return True > return False > > >>> check(49) > True > >>> check(50) > False > > >>> r,t = 1, 100 > >>> (-(2*r - 1) + pow(pow((2*r - 1), 2) + 4*2*t, 0.5))/4.0 ## Note > that this is the closed formula. > 50.0 > > > I wonder what's causing such error? Is it because of calculation of big > numbers? > Anyhow, in seeing this I managed to submit for A small. I changed my code > abit using while loop and tweaking alittle and submitted large; but got it > wrong in the end. > > I'm currently using Python 2.7. > Any reason why its behaving so weirdly? > > > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to google-code+unsubscr...@googlegroups.com. > To post to this group, send email to google-code@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[gcj] BullsEye Problem - Python Troubleshooting help!
I used the following logic for the problem - Let k be the required answer. Then, (R+1)^2 - R^2 = 2R + 1 amount of paint to paint the first circle (R+3)^2 - (R+2)^2 = 2R + 5 amount of paint to paint the second circle. ... and so on - we get total k equations. Now, adding the k equations, and putting the RHS <= t we get the following quadratic inequality: 2k^2 + (2R - 1)k - t <= 0. So I managed to get a closed formula for this problem. However, when I ran my code to the test cases given, it solved them all correctly, except for the last one. I double checked my soln; seemed there was nothing at all but a problem in Python (I think.). Substituting k = 49 works, but k = 50 in (*) makes RHS > 0. [Check the following code] >>> def check(k): r,t = 1, 100 if 2*k*k + 2*(r-1)*k - t <= 0: return True return False >>> check(49) True >>> check(50) False >>> r,t = 1, 100 >>> (-(2*r - 1) + pow(pow((2*r - 1), 2) + 4*2*t, 0.5))/4.0 ## Note that this is the closed formula. 50.0 I wonder what's causing such error? Is it because of calculation of big numbers? Anyhow, in seeing this I managed to submit for A small. I changed my code abit using while loop and tweaking alittle and submitted large; but got it wrong in the end. I'm currently using Python 2.7. Any reason why its behaving so weirdly? -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.