Ruby練習五日目(Hanafuda Shuffle)
ACM/ICPC国内予選突破の手引きより問題を選んで実装してみることに。まずは最初ということもあり、一番上に書かれている難易度の低そうなHanahuda Shuffleから挑戦してみることにした。
while true n, r = ARGF.gets.chomp.split(/ /).map { |n| n.to_i } if n == 0 && r == 0 break end # 札の初期化。添字が小さい方を上とする cards = Array.new(n) { |i| n - i } # shuffle r.times { |i| p, c = ARGF.gets.chomp.split(/ /).map { |n| n.to_i } p -= 1 ptmp = cards[0...p] c.times { |j| cards[j] = cards[j + p] } p.times { |j| cards[j + c] = ptmp[j] } } puts cards[0] end