Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created August 2, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/78b9e1e80d8a1c8aac805eaf7b5c61c3 to your computer and use it in GitHub Desktop.
Save whatalnk/78b9e1e80d8a1c8aac805eaf7b5c61c3 to your computer and use it in GitHub Desktop.
ICPC Domestic 2009 Next Mayer
# ICPC Domestic 2009
# Next Mayer
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1159
while true
n, p_ = gets.chomp.split(" ").map(&:to_i)
break if n == 0 && p_ == 0
cand = Array.new(n, 0)
stone = p_
(0...n).cycle do |i|
if stone > 0 then
stone -= 1
cand[i] += 1
if cand[i] == p_ then
puts i
break
end
else
if cand[i] > 0 then
stone += cand[i]
cand[i] = 0
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment