0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RubyでAtCoder ABC234(A, B, C)を解いてみた

Posted at

はじめに

Webエンジニアを目指して、RubyやRailsをいじってます。
今回は、RubyでAtCoder ABC234のA, B, Cを解きました。備忘録として解き方をまとめていきたいと思います。

A - Weird Function

a-234.rb
def f(x)
  return x ** 2 + 2 * x + 3
end

t = gets.to_i
puts f(f(f(t) + t) + f(f(t)))

B - Longest Segment

b-234.rb
n = gets.to_i
array = Array.new(n){ gets.split.map(&:to_i) }

puts array.combination(2).map{ Math.hypot(_1[0] - _2[0], _1[1] - _2[1])}.max

解説

combinationメソッドを使ってそれぞれの組み合わせにおける距離の最大値を求めます。

C - Happy New Year!

c-234.rb
k = gets.to_i.to_s(2)
puts k.to_i * 2

与えられた整数を2進数にして、その値を2倍したものが答えとなります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?