結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー @abcde@abcde
提出日時 2019-05-30 00:00:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,872 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 167,316 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 18:46:56
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// 正方形か否かを判定.
// @param x1: X座標.
// @param y1: Y座標.
// @param x2: X座標.
// @param y2: Y座標.
// @param x3: X座標.
// @param y3: Y座標.
// @param x4: X座標.
// @param y4: Y座標.
// @return:
//       true: 正方形を描ける, false: 正方形を描けない.
bool isSquare(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
    
    // 4辺の長さの2乗を計算.
    int e1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    int e2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
    int e3 = (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4);
    int e4 = (x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1);
    
    // 4辺とも等しいか判定.
    if(e1 == e2 && e2 == e3 && e3 == e4 && e4 == e1) return true;
    else                                             return false;

}

int main() {
    
    // 1. 入力情報取得.
    int x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    
    // 2. 正方形が描けるか否か.
    // 2-1. (x1, y1) と (x4, y4) が対角線の場合.
    int x4, y4;
    x4 = x2 + x3 - x1, y4 = y2 + y3 - y1;
    bool ans = isSquare(x1, y1, x2, y2, x4, y4, x3, y3);
    if(ans){
        cout << x4 << " " << y4 << endl;
        return 0;
    }
    
    // 2-2. (x1, y1) と (x2, y2) が対角線の場合.
    x4 = x1 + x2 - x3, y4 = y1 + y2 - y3;
    ans = isSquare(x1, y1, x4, y4, x2, y2, x3, y3);
    if(ans){
        cout << x4 << " " << y4 << endl;
        return 0;
    }

    // 2-3. (x1, y1) と (x3, y3) が対角線の場合.
    x4 = x1 + x3 - x2, y4 = y1 + y3 - y2;
    ans = isSquare(x1, y1, x4, y4, x3, y3, x2, y2);
    if(ans){
        cout << x4 << " " << y4 << endl;
        return 0;
    }
    
    // 2-4. 上記以外.
    cout << "-1" << endl;

    // 3. 後処理.
    return 0;
    
}
0