Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 1, 2017 09:21
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/0b3cbf56de1e753d8eabcd4b64d4448a to your computer and use it in GitHub Desktop.
Save whatalnk/0b3cbf56de1e753d8eabcd4b64d4448a to your computer and use it in GitHub Desktop.
天下一プログラマーコンテスト2017
puts gets.chomp.split("").map(&:to_i).inject(:+)
n = gets.chomp.to_i
arr = []
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
arr << [a, b]
end
arr.sort_by!{|x| x[0]}
puts arr.last[0] + arr.last[1]
N = gets.chomp.to_i
if N.even?
# p [N / 4, N * N * (N / 2) / (N * N + N * N / 2 + N * N / 2)]
puts "#{N} #{N} #{N / 2}"
else
(1..3500).each do |h|
(1..3500).each do |n|
if h.even? || n.even? then
x = N * h * n
y = (4 * h * n - N * n - N * h)
if y > 0 && x % y == 0
# p [N / 4, h * n * (x / y) / (h * n + n * x / y + h * x / y)]
puts "#{h} #{n} #{x / y}"
exit
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment