Created
August 2, 2017 18:29
-
-
Save whatalnk/78b9e1e80d8a1c8aac805eaf7b5c61c3 to your computer and use it in GitHub Desktop.
ICPC Domestic 2009 Next Mayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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