2019-08-01から1ヶ月間の記事一覧

AtCoder/ABC138

https://atcoder.jp/contests/abc138 A - Red or Not puts (gets.to_i >= 3200) ? gets.chomp : "red" B - Resistors in Parallel gets as = gets.split.map(&:to_i) puts Rational(1, as.map {|i| Rational(1, i)}.inject(:+)).to_f C - Alchemist gets as …

ある双曲線の整数解

36*x^2-4*x-71*y^2+8=0 の整数解の導出。Ruby でできるだけ解いてみる。 solve.rb dir = [[1, 0], [0, 1], [-1, 0], [0, -1]] x = y = 0 step = 1 f = ->{p [x, y] if 36 * x ** 2 - 4 * x - 71 * y ** 2 + 8 == 0} add = ->(i) { dx, dy = dir[i] x += dx y…

AtCoder/ABC137

A - +-x a, b = gets.split.map(&:to_i) puts [a + b, a - b, a * b].max B - One Clue k, x = gets.split.map(&:to_i) puts [*x - k + 1..x + k - 1].join(" ") C - Green Bin words = gets.to_i.times.map {gets.chomp.chars.sort.join}.group_by(&:itself…

AtCorder/ABC(その1)

ABC001 A - 積雪深差 puts gets.to_i - gets.to_i B - 視程の通報 ans = case (m = gets.to_i) when 0...100 then 0 when 100..5000 then m / 100 when 6000..30000 then m / 1000 + 50 when 35000..70000 then (m / 1000 - 30) / 5 + 80 else 89 end puts s…