Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active November 6, 2016 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/4f062774b1f723da1d71e0d131403883 to your computer and use it in GitHub Desktop.
Save whatalnk/4f062774b1f723da1d71e0d131403883 to your computer and use it in GitHub Desktop.
AtCoder DDCP 2016 予選 [Ruby]
a, b, c = gets.chomp.split(" ").map(&:to_f)
puts c / a * b
r, n, m = gets.chomp.split(" ").map(&:to_i)
w = 2 * r.to_f / n
aa = [0]
(1..(n - 1)).each do |i|
a = w * i < r ? r - w * i : w * i - r
aa << Math.sqrt(r ** 2 - a ** 2) * 2
end
aa << 0
ret = 0
(1..(n + m - 1)).each do |i|
if i < 0 || i > n then
ret += aa[i - m]
elsif i - m < 0 || i - m > n then
ret += aa[i]
else
ret += [aa[i], aa[i - m]].max
end
end
puts ret
n, k = gets.chomp.split(" ").map(&:to_i)
aa = gets.chomp.split(" ").map(&:to_i)
h = Hash.new(0)
aa.each do |x|
a = x.gcd(k)
h[a] += 1
end
ret = 0
h.keys.repeated_combination(2).each do |a, b|
next if (a * b) % k != 0
if a == b then
ret += h[a] * (h[b] - 1) / 2
else
ret += h[a] * h[b]
end
end
puts ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment