Create a gist now

Instantly share code, notes, and snippets.

Codeforces #328 Div2
# [Problem - 592A - Codeforces](http://codeforces.com/problemset/problem/592/A)
field = []
while line = gets
field << line.chomp.split("")
end
field = field.transpose
stepA = []
stepB = []
field.each do |r|
a = r.rindex("W")
b = r.rindex("B")
unless b.nil? then
if a.nil? or (a < b) then
stepB << 7 - b
end
end
a = r.index("W")
b = r.index("B")
unless a.nil? then
if b.nil? or (a < b) then
stepA << a
end
end
end
if stepB.empty? or (stepA.min <= stepB.min) then
puts "A"
elsif stepA.empty? or (stepA.min > stepB.min) then
puts "B"
end
# [Problem - 592B - Codeforces](http://codeforces.com/problemset/problem/592/B)
n = gets.chomp.to_i
if n == 3 then
puts 1
else
a1 = 1
4.upto(n).each do |a|
a1 += 3 + 2*(a-4)
end
puts a1
end
# [Problem - 592C - Codeforces](http://codeforces.com/problemset/problem/592/C)
t, w, b = gets.chomp.split(" ").map(&:to_i)
res = 0
(1..t).each do |i|
ww = i / w
www = w * ww
bb = i / b
bbb = b * bb
if www ==bbb then
res += 1
end
end
puts Rational(res, t)
@whatalnk
Owner
whatalnk commented Nov 5, 2015
  • A
  • B
  • C
  • D
  • E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment