dashohoxha

bullseye.rb

Apr 26th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.38 KB | None | 0 0
  1. # My solution to the problem:
  2. # https://code.google.com/codejam/contest/2418487/dashboard#s=p0
  3.  
  4. def solve(r, t)
  5.   n = (-2*r + 1.0 + Math::sqrt((2*r - 1)**2 + 8*t)) / 4.0
  6.   n = n.ceil
  7.   while 2*n*n + n*(2*r - 1) > t
  8.     n -= 1
  9.   end
  10.   return n
  11. end
  12.  
  13. C = gets.to_i
  14. for c in 1..C
  15.   r, t = gets.chomp.split.map { |x| x.to_i }
  16.   n = solve(r, t)
  17.   puts "Case ##{c}: #{n}"
  18. end
Advertisement
Add Comment
Please, Sign In to add comment