Last active
November 6, 2016 03:36
-
-
Save whatalnk/4f062774b1f723da1d71e0d131403883 to your computer and use it in GitHub Desktop.
AtCoder DDCP 2016 予選 [Ruby]
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
a, b, c = gets.chomp.split(" ").map(&:to_f) | |
puts c / a * b |
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
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 |
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, 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