2012-09-01から1ヶ月間の記事一覧

Coderforces#137 (Div. 2 - A)

Rubyの勉強がてらにCodeforcesの問題を解いてみた。http://www.codeforces.com/contest/222/problem/A def solve(k, a) t = a[k - 1] # kより後ろの配列 other = a[k - 1 .. -1] other.each do |i| if i != t return -1 end end c = 0 (k - 1).downto(0) do …

Coderforces#139 (Div. 2 - A)

最近プログラミングしてなかったので、頭の体操がてらにCodeforcesの問題を解いてみた。 http://www.codeforces.com/contest/225/problem/A def solve(x, faces) faces.each do |a, b| if (a == b) or (a == x) or (b == x) or ((a + b) == 7) or ((a + x) =…