結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-08-11 15:08:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 111 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-26 22:20:57
合計ジャッジ時間 4,287 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
13,312 KB
testcase_01 AC 94 ms
13,184 KB
testcase_02 AC 93 ms
13,440 KB
testcase_03 AC 92 ms
13,312 KB
testcase_04 AC 90 ms
13,312 KB
testcase_05 AC 87 ms
13,312 KB
testcase_06 AC 93 ms
13,184 KB
testcase_07 AC 90 ms
13,312 KB
testcase_08 AC 102 ms
13,440 KB
testcase_09 AC 107 ms
13,440 KB
testcase_10 AC 109 ms
13,184 KB
testcase_11 AC 110 ms
13,312 KB
testcase_12 AC 108 ms
13,312 KB
testcase_13 AC 107 ms
13,312 KB
testcase_14 AC 111 ms
13,184 KB
testcase_15 AC 105 ms
13,312 KB
testcase_16 AC 108 ms
13,440 KB
testcase_17 AC 106 ms
13,312 KB
testcase_18 AC 103 ms
13,184 KB
testcase_19 AC 106 ms
13,184 KB
testcase_20 AC 105 ms
13,312 KB
testcase_21 AC 106 ms
13,312 KB
testcase_22 AC 107 ms
13,440 KB
testcase_23 AC 106 ms
13,440 KB
testcase_24 AC 109 ms
13,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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