結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー ふーらくたるふーらくたる
提出日時 2016-08-10 22:55:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,925 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 69,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:20:48
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <utility>
#include <assert.h>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

// 二次元上の点を表す型
class Point {
public:
    int x, y;

    Point(int x = 0, int y = 0) : x(x), y(y) {}

    Point operator+(const Point& p) {
        return Point(x + p.x, y + p.y);
    }

    Point operator-(const Point& p) {
        return Point(x - p.x, y - p.y);
    }

    Point operator*(int k) {
        return Point(x * k, y * k);
    }

    Point operator/(int k) {
        return Point(x / k, y / k);
    }

    int norm() {
        return x * x + y * y;
    }

    int abs() {
        return sqrt(norm());
    }

    bool operator<(const Point& p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator==(const Point& p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

// ベクトルを表す構造体
typedef Point Vector;

// ベクトルのノルムを計算する
int norm(Vector a) {
    return a.x * a.x + a.y * a.y;
}

// ベクトル a とベクトル b の内積を求める
int dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

int main() {
    int x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    Point p1 = Point(x1, y1), p2 = Point(x2, y2),
          p3 = Point(x3, y3);
    Vector v1 = p2 - p1, v2 = p3 - p1, v3 = v2 - v1, v4 = v1 - v2;

    Point p4;
    if (dot(v1, v2) == 0 && norm(v1) == norm(v2)) {
        p4 = p1 + v1 + v2;
        cout << p4.x << " " << p4.y << endl;
    } else if (dot(v1, v3) == 0 && norm(v1) == norm(v3)) {
        p4 = p1 + v3;
        cout << p4.x << " " << p4.y << endl;
    } else if (dot(v2, v4) == 0 && norm(v2) == norm(v4)) {
        p4 = p1 + v4;
        cout << p4.x << " " << p4.y << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}
0