結果
| 問題 |
No.55 正方形を描くだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2020-05-08 22:32:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,614 bytes |
| コンパイル時間 | 1,847 ms |
| コンパイル使用メモリ | 175,552 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 00:57:59 |
| 合計ジャッジ時間 | 2,484 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int intpow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans *= a;
a *= a;
b /= 2;
}
return ans;
}
int len_sqrt(vector<pair<int, int>>& V, int i) {
return intpow(abs(V[i].first - V[(i + 1) % 4].first), 2) + intpow(abs(V[i].second - V[(i + 1) % 4].second), 2);
}
bool check(vector<pair<int, int>> V) {
if (
len_sqrt(V, 0) == len_sqrt(V, 1) && len_sqrt(V, 1) == len_sqrt(V, 2) && len_sqrt(V, 2) == len_sqrt(V, 3) && V[0] != V[2] && V[1] != V[3] && (V[1].first - V[0].first) * (V[3].first - V[0].first) + (V[1].second - V[0].second) * (V[3].second - V[0].second) == 0) {
return true;
}
return false;
}
int main() {
vector<pair<int, int>> V(4);
for (int i = 0; i < 3; i++) {
int X, Y;
cin >> X >> Y;
V[i] = {X, Y};
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) continue;
V[3] = {V[i].first + V[j].first - V[3 - i - j].first,
V[i].second + V[j].second - V[3 - i - j].second};
auto V_copy = V;
sort(V_copy.begin(), V_copy.end());
bool flag = false;
do {
if (check(V_copy)) {
flag = true;
break;
};
} while (next_permutation(V_copy.begin(), V_copy.end()));
if (flag) {
cout << V[3].first << " " << V[3].second << endl;
return 0;
}
}
}
cout << -1 << endl;
}
maine_honzuki