SHARE
TWEET

Untitled

a guest Sep 21st, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. arr = [] # 配列の初期化
  2. while (gets) # 標準入力があるかぎり実行
  3.   arr << $_.chomp
  4. end
  5. (0..arr.length-1).each do |i|
  6.   arr[i] = arr[i].split
  7.   arr[i] = arr[i].map { |n| n.to_i }
  8. end
  9. arr.each do |n|
  10.   n.push(n[0]+1)
  11. end
  12.  
  13. # 現在地
  14. present_loc = [1, arr[0][0]]
  15. m = arr[0][2]
  16.  
  17. arr.delete_at(0)
  18.  
  19. m.times do
  20.     root_choice_a = arr.select {  |a| a[0] == present_loc[0] && a[1] <= present_loc[1] }
  21.     root_choice_b = arr.select {  |a| a[3] == present_loc[0] && a[2] <= present_loc[1] }
  22.     if root_choice_a.empty? && root_choice_b.empty?
  23.         break
  24.     end
  25.     root_choice = root_choice_a + root_choice_b
  26.     root = root_choice.map {
  27.         |a|
  28.         if a[0] == present_loc[0]
  29.             a[1]
  30.         else
  31.             a[2]
  32.         end
  33.         }
  34.     root_index = root.index(root.max)
  35.    
  36.     action = root_choice[root_index]
  37.     if present_loc[0] == action[0]
  38.       loc_0 = action[3]
  39.       loc_1 = action[2]
  40.     else
  41.       loc_0 = action[0]
  42.       loc_1 = action[1]
  43.     end
  44.     present_loc[0] = loc_0
  45.     present_loc[1] = loc_1
  46.     arr.delete(action)
  47. end
  48.  
  49. puts present_loc[0]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top