結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー lunnear
提出日時 2019-02-11 04:42:30
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,347 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 59,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 11:51:51
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>

class Vector2
{
public:
    Vector2(short x = 0, short y = 0):x(x), y(y){}
    
public:
    short x, y;
    
public:
    short LengthSq(){return (x * x + y * y);}
    float Length(){return sqrtf(x * x + y * y);}
    
public:
    Vector2 operator+(Vector2 &a){return Vector2(x + a.x, y + a.y);}
    Vector2 operator-(Vector2 &a){return Vector2(x - a.x, y - a.y);}
};

int main()
{
    Vector2 v[4];
    for(int i = 0; i < 3; i++)
    {
        std::cin >> v[i].x >> v[i].y;
    }
    
    Vector2 e[5];
    e[0] = v[1] - v[0];
    e[1] = v[2] - v[1];
    e[2] = v[0] - v[2];
    

    if(e[0].LengthSq() == e[1].LengthSq())
    {
        v[3] = v[0] + e[1];
        
        e[3] = v[2] - v[0];
        e[4] = v[3] - v[1];
    }
    else if(e[1].LengthSq() == e[2].LengthSq())
    {
        v[3] = v[1] + e[2];
        
        e[3] = v[1] - v[0];
        e[4] = v[3] - v[2];
    }
    else if(e[2].LengthSq() == e[0].LengthSq())
    {
        v[3] = v[2] + e[0];
        
        e[3] = v[2] - v[1];
        e[4] = v[3] - v[0];
    }
    else
    {
        std::cout << "-1" << std::endl;
        return 0;
    }
    

    if(e[3].LengthSq() != e[4].LengthSq())
    {
        std::cout << "-1" << std::endl;
        return 0;
    }
    
    std::cout << v[3].x << " " << v[3].y << std::endl;
    return 0;
}
0