結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー はむ吉🐹
提出日時 2016-08-11 15:08:45
言語 Ruby
(3.4.1)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-11-14 13:55:34
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/env ruby

require "matrix"


EPS = 1e-8


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


def translation_matrix(delta)
    m = Matrix[[1, 0, delta[0]], [0, 1, delta[1]], [0, 0, 1]]
    return m
end


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


def find_last_point(point1, point2, point3)
    ps = [point1, point2, point3]
    ps.permutation(3) {|p1, p2, p3|
        q3 = rotate_around(p2, p1, Math::PI / 2.0)
            return rotate_around(p3, p2, Math::PI / 2.0) if (p3 - q3).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
0