fork(1) download
  1. STDOUT.sync = true # DO NOT REMOVE!
  2.  
  3. # Upper-left and lower-right corners bounding the search area.
  4. # @note Intervals are half-open: [x0,x1); [y0,y1)
  5. x0, y0 = 0, 0
  6. x1, y1 = gets.split.map(&:to_i)
  7. # Maximum number of turns before game over.
  8. n = gets.to_i
  9. # Batman's starting position.
  10. px, py = gets.split.map(&:to_i)
  11.  
  12. # Game loop.
  13. n.times do
  14. # Direction of the bomb from Batman's current position.
  15. # (U, UR, R, DR, D, DL, L or UL)
  16. bomb_dir = gets.chomp
  17. # Reduce search area.
  18. bomb_dir.each_char do |dir|
  19. case dir
  20. when ?U then y1 = py
  21. when ?D then y0 = py+1
  22. when ?L then x1 = px
  23. when ?R then x0 = px+1
  24. end
  25. end
  26. # Set position to center of search area.
  27. px = (x0 + x1) / 2
  28. py = (y0 + y1) / 2
  29. # Emit new position.
  30. puts "#{px} #{py}"
  31. end
Success #stdin #stdout 0.01s 8040KB
stdin
10 10
3
0 0
DR
U
L
stdout
5 5
5 3
3 3