Last active
February 2, 2016 05:14
-
-
Save whatalnk/91a6fc9262da270a3c2d to your computer and use it in GitHub Desktop.
Codeforces #341 Div2
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
n = gets.chomp.to_i | |
a = gets.chomp.split(" ").map(&:to_i) | |
aoddmin = a.select{|x| x.odd?}.min | |
asum = a.inject(:+) | |
if asum.even? then | |
puts asum | |
else | |
puts asum - aoddmin | |
end |
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
n = gets.chomp.to_i | |
coords1 = Hash.new(0) | |
coords2 = Hash.new(0) | |
n.times do | |
coord = gets.chomp.split(" ").map(&:to_i) | |
coords1[coord[1] - coord[0]] += 1 | |
coords2[coord[1] + coord[0]] += 1 | |
end | |
def comb(n, k) | |
return ((n - k + 1)..n).inject(:*) / (1..k).inject(:*) | |
end | |
res = 0 | |
coords1.values.each do |v| | |
res += comb(v, 2) | |
end | |
coords2.values.each do |v| | |
res += comb(v, 2) | |
end | |
puts res |
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
n, p = gets.chomp.split(" ").map(&:to_i) | |
lr = [] | |
n.times do | |
lr << gets.chomp.split(" ").map(&:to_i) | |
end | |
res = 0 | |
n.times do |i| | |
l1, r1 = lr[i] | |
l2, r2 = lr[i - 1] | |
a1 = r1 / p - (l1 - 1) / p | |
a2 = r2 / p - (l2 - 1) / p | |
res += 2000 * (1 - (r1 - l1 + 1 - a1) / (r1 - l1 + 1).to_f * (r2 - l2 + 1 - a2) / (r2 - l2 + 1).to_f) | |
end | |
puts res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment