結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー alpha_virginisalpha_virginis
提出日時 2016-02-25 00:22:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,471 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 66,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:18:12
合計ジャッジ時間 1,388 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   scanf("%d %d", &p[0].x, &p[0].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:35:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   scanf("%d %d", &p[1].x, &p[1].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d %d", &p[2].x, &p[2].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

template<typename T>
class Vector2 {
public:
  Vector2(){}
  Vector2(T x_, T y_) : x(x_), y(y_) {}
  T Norm2();
  T x, y;
};

template<typename T> Vector2<T> operator + (const Vector2<T>& left, const Vector2<T>& right) {
  return Vector2<T>(left.x + right.x, left.y + right.y);
}

template<typename T> Vector2<T> operator - (const Vector2<T>& left, const Vector2<T>& right) {
  return Vector2<T>(left.x - right.x, left.y - right.y);
}

template<typename T>
T Vector2<T>::Norm2() {
  return x * x + y * y;
}

int main() {

  Vector2<int> p[3];
  scanf("%d %d", &p[0].x, &p[0].y);
  scanf("%d %d", &p[1].x, &p[1].y);
  scanf("%d %d", &p[2].x, &p[2].y);

  Vector2<int> v[3][3];
  for(int i = 0; i < 3; ++i) {
    for(int j = 0; j < 3; ++j) {
      v[i][j] = p[j] - p[i];
    }
  }

  Vector2<int> res;
  bool exist = false;
  if( v[0][1].Norm2() == v[0][2].Norm2() and v[0][1].Norm2() * 2 == v[1][2].Norm2() ) {
    res = p[2] + p[1] - p[0]; exist = true;
  }
  if( v[1][0].Norm2() == v[1][2].Norm2() and v[1][0].Norm2() * 2 == v[0][2].Norm2() ) {
    res = p[2] + p[0] - p[1]; exist = true;
  }
  if( v[2][0].Norm2() == v[2][1].Norm2() and v[2][0].Norm2() * 2 == v[0][1].Norm2() ) {
    res = p[1] + p[0] - p[2]; exist = true;
  }

  if( exist ) {
    printf("%d %d\n", res.x, res.y);
  }
  else {
    printf("-1\n");
  }    
  
  return 0;
}
0