Area of the first white circle is pi* r*r Area of first black circle that includes first white circle is pi * (r+1) * (r+1)
So area of first black strip is pi * (r+1) * (r+1) - pi *r *r If you continue doing this then area of second black strip is pi * (r+3) * (r+3) - pi * (r+2) * (r+2) So total area of n black strips is (pi * (r+1) * (r+1) - pi * r * r) + (pi * (r+3) * (r+3) - pi * (r+2) * (r+2)) + ....... I will remove pi as pi is common for all. So above expression can be written as (r*r + 2*r + 1 - r *r) + (r*r + 6 * r + 9 - r * r + 4 * r + 4) + ...... ( 2* r + 1) + ( 2*r + 5) + (2r + 9) + ..... 2 * r * n + (1 + 5 + 9 + ....) 2* r * n + ( 1 + (1 + 4) + ( 1 + 8 ) + ....) 2 * r * n + ( 1 * n + ( 4 + 8 + 12 + ...)) 2 * r * n + 1 * n + 4 * n * ( n-1) /2 2 * r * n + n + 2 * n * (n -1) This is the formula everyone used to do the binary search = On Sat, Apr 27, 2013 at 1:04 PM, newbie007 <lescoutinh...@gmail.com> wrote: > Hi, > > I understand that they're using binary search, but I don't know how can it > get to the solution. > Could someone be very nice and explain the code below, please? > This is from coder "wata": > > void solve() { > long left = 0, right = 1L << 40; > while (right - left > 1) { > long n = (left + right) / 2; > if ((double)(2 * r + 1) * n + 2.0 * n * (n - 1) > 1.5 * t) > { > right = n; > } else if ((2 * r + 1) * n + 2 * n * (n - 1) > t) { > right = n; > } else { > left = n; > } > } > System.out.println(left); > } > > Why those values, why 1.5? Man, I don't understand this code :( > > Em sábado, 27 de abril de 2013 05h42min58s UTC-3, Vaibhav Tulsyan > escreveu: > > I was seeing the solutions of the top 10 contestants for the large input > of Bull's Eye. They all seem to have used some method involving variables > like beginning,end and mid. Can anybody explain to me what method they've > applied exactly? > > I just used basic maths to solve it. They seem to have used some better > algorithm. > > -- > 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/-/nB8pI_xLLzAJ. > 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.