結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー koyoprokoyopro
提出日時 2015-09-22 14:45:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,008 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 72,984 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:15:47
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 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 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 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<math.h>
#include<vector>
#include <array>
#include <algorithm>
#include <queue>
#include <numeric>
#include <map>

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) //printf(__VA_ARGS__)

typedef pair<int, int> pos;
int pos::*x = &pos::first;
int pos::*y = &pos::second;

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

pos p1, p2, p3;

int len2(pos p1, pos p2) {
    return pow(p1.*x - p2.*x, 2) + pow(p1.*y - p2.*y, 2);
}

signed main()
{
    cin >> p1.*x >> p1.*y >> p2.*x >> p2.*y >> p3.*x >> p3.*y;
    int len12 = len2(p1, p2);
    int len23 = len2(p2, p3);
    int len31 = len2(p1, p3);
    pos center, h1, h2;
    if (len12 == len23) {
        // 中心: 2
        center = p2;
        h1 = p1;
        h2 = p3;
    } else if (len23 == len31) {
        // 中心: 3
        center = p3;
        h1 = p1;
        h2 = p2;
    } else if (len31 == len12) {
        // 中心: 1
        center = p1;
        h1 = p3;
        h2 = p2;
    } else {
        // 正方形にならない場合
        cout << -1 << endl;
        return 0;
    }
    // 90°じゃない場合...?
    pos p4, vec, vec2;
    vec.*x = h1.*x - center.*x;
    vec.*y = h1.*y - center.*y;

    vec2.*x = h2.*x - center.*x;
    vec2.*y = h2.*y - center.*y;

    if (vec2.*x * vec.*x + vec2.*y * vec.*y != 0) {
        // 内積が0でない: 90°じゃない
        cout << -1 << endl;
        return 0;
    }

    p4.*x = h2.*x + vec.*x;
    p4.*y = h2.*y + vec.*y;
    cout << p4.*x << " " << p4.*y << endl;

    return 0;
}
0