結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-08-20 09:46:31
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,487 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 52,776 KB
最終ジャッジ日時 2024-04-27 02:09:40
合計ジャッジ時間 584 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:3: error: ‘vector’ was not declared in this scope
   21 |   vector<int> ds = { p1.dist2(p2),
      |   ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:21:10: error: expected primary-expression before ‘int’
   21 |   vector<int> ds = { p1.dist2(p2),
      |          ^~~
main.cpp:24:8: error: ‘ds’ was not declared in this scope
   24 |   sort(ds.begin(), ds.end());
      |        ^~
main.cpp:26:11: error: ‘b’ was not declared in this scope
   26 |   if(a != b || a + b != c) {
      |           ^
main.cpp:26:25: error: ‘c’ was not declared in this scope
   26 |   if(a != b || a + b != c) {
      |                         ^
main.cpp:19:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   int x1, y1, x2, y2, x3, y3; scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

struct Point {
public:
  int x, y;
  bool operator==(const Point& other) const { return x == other.x && y == other.y; }
  int dist2(const Point& other) const {
    int xx = x - other.x, yy = y - other.y;
    return xx * xx + yy * yy;
  }
};

int main(void) {
  int x1, y1, x2, y2, x3, y3; scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
  Point p1({x1, y1}), p2({x2, y2}), p3({x3, y3});
  vector<int> ds = { p1.dist2(p2),
                     p2.dist2(p3),
                     p3.dist2(p1) };
  sort(ds.begin(), ds.end());
  int a = ds[0], b = ds[1], c = ds[2];
  if(a != b || a + b != c) {
    puts("-1");
    return 0;
  }
  for(int x : range(-300, 300)) {
    for(int y : range(-300, 300)) {
      if(x == x1 && y == y1) { continue; }
      if(x == x2 && y == y2) { continue; }
      if(x == x3 && y == y3) { continue; }
      Point p({x, y});
      int d1 = p.dist2(p1),
          d2 = p.dist2(p2),
          d3 = p.dist2(p3);
      int check = 0;
      if(d1 == a) { check++; }
      if(d2 == a) { check++; }
      if(d3 == a) { check++; }
      if(check == 2) {
        printf("%d %d\n", x, y);
        return 0;
      }
    }
  }
  puts("(ΦωΦ)");
  return 0;
}
0