fork 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 (ignored).
  8. n = gets.to_i
  9. # Batman's starting position.
  10. px, py = gets.split.map(&:to_i)
  11.  
  12. # Game loop.
  13. loop 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
  17. break if bomb_dir.nil?
  18. # Reduce search area.
  19. bomb_dir.chomp.each_char do |dir|
  20. case dir
  21. when ?U then y1 = py
  22. when ?D then y0 = py+1
  23. when ?L then x1 = px
  24. when ?R then x0 = px+1
  25. end
  26. end
  27. # Set position to center of search area.
  28. px = (x0 + x1) / 2
  29. py = (y0 + y1) / 2
  30. # Emit new position.
  31. puts "#{px} #{py}"
  32. end
Success #stdin #stdout 0.02s 8024KB
stdin
748 341
10
738 49
DL
UR
DR
DL
DL
DL
DL
U
stdout
369 195
554 122
646 159
600 177
577 186
566 191
560 193
560 192