結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
![]() |
提出日時 | 2015-09-22 14:45:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,008 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 72,740 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 13:51:42 |
合計ジャッジ時間 | 1,591 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#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; }