Skip to content

Instantly share code, notes, and snippets.

@inage
Created December 7, 2013 14:44
Show Gist options
  • Select an option

  • Save inage/7843216 to your computer and use it in GitHub Desktop.

Select an option

Save inage/7843216 to your computer and use it in GitHub Desktop.
区間スケジューリング問題
## 区間スケジューリング問題
## http://rubyfiddle.com/riddles/da7c6
n = 5
s = [1, 2, 4, 6, 8]
t = [3, 5, 7, 9, 10]
a = []
ans = 0
last = 0
n.times{|i|
a[i] = [t[i],s[i]]
}
a.sort!
n.times{|i|
if last < a[i][1]
ans += 1
last = a[i][0]
end
}
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment