Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arr = [] # 配列の初期化
- while (gets) # 標準入力があるかぎり実行
- arr << $_.chomp
- end
- (0..arr.length-1).each do |i|
- arr[i] = arr[i].split
- arr[i] = arr[i].map { |n| n.to_i }
- end
- arr.each do |n|
- n.push(n[0]+1)
- end
- # 現在地
- present_loc = [1, arr[0][0]]
- m = arr[0][2]
- arr.delete_at(0)
- m.times do
- root_choice_a = arr.select { |a| a[0] == present_loc[0] && a[1] <= present_loc[1] }
- root_choice_b = arr.select { |a| a[3] == present_loc[0] && a[2] <= present_loc[1] }
- if root_choice_a.empty? && root_choice_b.empty?
- break
- end
- root_choice = root_choice_a + root_choice_b
- root = root_choice.map {
- |a|
- if a[0] == present_loc[0]
- a[1]
- else
- a[2]
- end
- }
- root_index = root.index(root.max)
- action = root_choice[root_index]
- if present_loc[0] == action[0]
- loc_0 = action[3]
- loc_1 = action[2]
- else
- loc_0 = action[0]
- loc_1 = action[1]
- end
- present_loc[0] = loc_0
- present_loc[1] = loc_1
- arr.delete(action)
- end
- puts present_loc[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement