結果
| 問題 |
No.55 正方形を描くだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-08-11 20:02:04 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 5,000 ms |
| コード長 | 1,556 bytes |
| コンパイル時間 | 61 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 13,440 KB |
| 最終ジャッジ日時 | 2024-11-14 13:55:38 |
| 合計ジャッジ時間 | 3,543 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
コンパイルメッセージ
Syntax OK
ソースコード
#!/usr/bin/env ruby
# yukicoder No.55 正方形を描くだけの簡単なお仕事です。
require "matrix"
EPS = 1e-8
# 原点を中心にした角angleだけの回転を表す行列を返す
def rotation_matrix(angle)
c = Math.cos angle
s = Math.sin angle
m = Matrix[[c, -s, 0], [s, c, 0], [0, 0, 1]]
return m
end
# delta = (dx, dy)だけ平行移動することを表す行列を返す
def translation_matrix(delta)
m = Matrix[[1, 0, delta[0]], [0, 1, delta[1]], [0, 0, 1]]
return m
end
# 点centerを中心に角angleだけ点pointを回転したものを返す
# -centerだけ平行移動 + 原点中心にangleだけ回転 + centerだけ平行移動
def rotate_around(center, point, angle)
m = translation_matrix(center)
m *= rotation_matrix(angle)
m *= translation_matrix([-center[0], -center[1]])
v = Vector[*point, 1]
a = m * v
return Vector[a[0], a[1]]
end
# p4を求める
# 存在しなければnilを返す
def find_last_point(point1, point2, point3)
ps = [point1, point2, point3]
ps.permutation(3) {|p1, p2, p3|
q1 = rotate_around(p2, p3, Math::PI / 2.0)
return rotate_around(p1, p2, Math::PI / 2.0) if (p1 - q1).r < EPS
}
return nil
end
def main()
x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_i)
point1 = Vector[x1, y1]
point2 = Vector[x2, y2]
point3 = Vector[x3, y3]
ans = find_last_point(point1, point2, point3)
if ans != nil
puts ans.map(&:round).to_a.join(" ")
else
puts (-1)
end
end
main
はむ吉🐹