結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
|
提出日時 | 2017-02-11 10:02:45 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,778 bytes |
コンパイル時間 | 749 ms |
コンパイル使用メモリ | 75,332 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 11:58:21 |
合計ジャッジ時間 | 1,894 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <iostream>#include <sstream>#include <vector>#include <array>#include <string>#include <algorithm>#include <map>#include <cmath>using namespace std;#define REP(i,first,last) for (int i=first;i<last;++i)#define MAX(x,y) (x > y ? x : y)#define MIN(x,y) (x < y ? x : y)typedef pair<int, int> p_ii;vector<p_ii> points;int get_distance(p_ii p_1, p_ii p_2){int x = pow(p_1.first - p_2.first, 2);int y = pow(p_1.second - p_2.second, 2);return x + y;}int main(){for (int i=0;i<3;i++) {p_ii p;cin >> p.first;cin >> p.second;points.push_back(p);}// 最初の点を適当に決め、残り二つのうちから距離が近い方を二番目の点にするp_ii p_1 = points[0];int dis_1 = get_distance(points[0], points[1]);int dis_2 = get_distance(points[0], points[2]);p_ii p_2 = MIN(dis_1, dis_2) == dis_1 ? points[1] : points[2];// 2点間のxとyの差から、正方形になるための点候補を四つ挙げるint x_dif = p_2.first - p_1.first;int y_dif = p_2.second - p_1.second;p_ii p_3 = {p_1.first + y_dif, p_1.second - x_dif};p_ii p_4 = {p_1.first - y_dif, p_1.second + x_dif};p_ii p_5 = {p_2.first + y_dif, p_2.second - x_dif};p_ii p_6 = {p_2.first - y_dif, p_2.second + x_dif};// 残りの一点が候補内にあれば正方形ができるp_ii rest_p = p_2 == points[1] ? points[2] : points[1];if (rest_p == p_3) {cout << p_5.first << " " << p_5.second << endl;} else if (rest_p == p_4) {cout << p_6.first << " " << p_6.second << endl;} else if (rest_p == p_5) {cout << p_3.first << " " << p_3.second << endl;} else if (rest_p == p_6) {cout << p_4.first << " " << p_4.second << endl;} else {cout << -1 << endl;}}