結果
問題 |
No.55 正方形を描くだけの簡単なお仕事です。
|
ユーザー |
|
提出日時 | 2020-07-17 16:12:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 392 ms / 5,000 ms |
コード長 | 1,461 bytes |
コンパイル時間 | 2,384 ms |
コンパイル使用メモリ | 208,164 KB |
最終ジャッジ日時 | 2025-01-11 21:47:26 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); double EPS = 1e-9; bool check(vector<pair<int, int> > ps) { double gx = 0, gy = 0; for (auto p: ps) { gx += p.first; gy += p.second; } gx /= 4, gy /= 4; vector<tuple<double, int, int> > rps; for (auto p: ps) { int x = p.first; int y = p.second; double theta = atan2(y-gy, x-gx); if (theta < 0) theta += 2 * PI; rps.emplace_back(theta, x, y); } sort(rps.begin(), rps.end()); bool ck = true; REP (i, 4) { int j = (i + 1) % 4; int k = (i + 3) % 4; int x1 = get<1>(rps[j]) - get<1>(rps[i]); int y1 = get<2>(rps[j]) - get<2>(rps[i]); int x2 = get<1>(rps[k]) - get<1>(rps[i]); int y2 = get<2>(rps[k]) - get<2>(rps[i]); ck &= x1 * x2 + y1 * y2 == 0; ck &= abs(hypot(x1, y1) - hypot(x2, y2)) < EPS; } return ck; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); vector<pair<int, int> > ps; REP (i, 3) { int x, y; cin >> x >> y; ps.emplace_back(x, y); } for (int x = -500; x <= 500; x++) { for (int y = -500; y <= 500; y++) { ps.emplace_back(x, y); if (check(ps)) { cout << x << " " << y << endl; return 0; } ps.pop_back(); } } cout << -1 << endl; return 0; }