結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー norioc
提出日時 2017-01-08 21:29:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 1,895 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 113,240 KB
実行使用メモリ 27,300 KB
最終ジャッジ日時 2024-12-17 18:17:50
合計ジャッジ時間 2,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

struct Vec2 {
    public int X { get; private set; }
    public int Y { get; private set; }

    public Vec2(int x, int y) {
        X = x;
        Y = y;
    }

    public static Vec2 operator+(Vec2 a, Vec2 b) {
        return new Vec2(a.X + b.X, a.Y + b.Y);
    }

    public static Vec2 operator-(Vec2 a, Vec2 b) {
        return new Vec2(a.X - b.X, a.Y - b.Y);
    }

    // a⋅b = |a||b|cosθ
    public int Dot(Vec2 other) {
        return X * other.X + Y * other.Y;
    }

    public int Cross(Vec2 other) {
        return X * other.Y - Y * other.X;
    }

    public double Magnitude() {
        return Math.Sqrt(X * X + Y * Y);
    }

    public override string ToString() {
        return string.Format("({0}, {1})", X, Y);
    }

    public static double Distance(Vec2 a, Vec2 b) {
        return (a - b).Magnitude();
    }
}

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static void Calc(Vec2 a, Vec2 b, Vec2 c) {
        foreach (var xs in new Vec2[][] { new[] { a, b, c }, new[] { b, a, c }, new[] { c, a, b } }) {
            // a:xs[0], b:xs[1], c:xs[2]
            var ab = xs[1] - xs[0];
            var ac = xs[2] - xs[0];
            if (ab.Dot(ac) == 0 && ab.Magnitude() == ac.Magnitude()) {
                var d = (ab + ac) + xs[0];
                Console.WriteLine("{0} {1}", d.X, d.Y);
                return;
            }
        }
        Console.WriteLine(-1); // not found
    }

    static void Main() {
        var xs = ReadInts();
        var a = new Vec2(xs[0], xs[1]);
        var b = new Vec2(xs[2], xs[3]);
        var c = new Vec2(xs[4], xs[5]);
        Calc(a, b, c);
    }
}
0