結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-10-21 23:13:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,314 bytes
コンパイル時間 2,829 ms
コンパイル使用メモリ 58,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 07:18:33
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,384 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
 
using namespace std;
 
#define fi first
#define se second
#define mp make_pair

typedef pair<int,int> P;
 
int len(P p1, P p2){
  return (p1.fi-p2.fi)*(p1.fi-p2.fi)+(p1.se-p2.se)*(p1.se-p2.se);
}
 
int check(P p1, P p2, P p3, P p4){
  if((p1.se-p2.se)*(p3.se-p4.se)==(p2.fi-p1.fi)*(p3.fi-p4.fi)){
    if((p1.fi+p2.fi)==(p3.fi+p4.fi)&&(p1.se+p2.se)==(p3.se+p4.se)){
      if(len(p1,p2)==len(p3,p4)){
        return 1;
      }
    }
  }
  return 0;
}
 
int main(){
  int x1,y1,x2,y2,x3,y3;
  cin>>x1>>y1>>x2>>y2>>x3>>y3;
  for(int y4 = -200; y4 <= 200; y4++){
    for(int x4 = -200; x4 <= 200; x4++){
      P p1 = mp(x1,y1);
      P p2 = mp(x2,y2);
      P p3 = mp(x3,y3);
      P p4 = mp(x4,y4);
      int res = 0;
      res |= check(p1,p2,p3,p4);
      res |= check(p1,p3,p2,p4);
      res |= check(p1,p4,p2,p3);
      if(res == 1){
        cout << x4 << " " << y4 << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

/*
範囲が狭いので4点目を全探索するインチキ解法が可能です。
もちろん範囲が-1000000000<=X,Y<=1000000000などでも答えはでます。
★3つにしてちゃんとした幾何の問題にしてもおもしろいかもしれません。
*/
0