結果
| 問題 |
No.55 正方形を描くだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2016-08-10 22:44:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,920 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 69,292 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 08:49:47 |
| 合計ジャッジ時間 | 1,384 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 3 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <utility>
#include <assert.h>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
// 二次元上の点を表す型
class Point {
public:
int x, y;
Point(int x = 0, int y = 0) : x(x), y(y) {}
Point operator+(const Point& p) {
return Point(x + p.x, y + p.y);
}
Point operator-(const Point& p) {
return Point(x - p.x, y - p.y);
}
Point operator*(int k) {
return Point(x * k, y * k);
}
Point operator/(int k) {
return Point(x / k, y / k);
}
int norm() {
return x * x + y * y;
}
int abs() {
return sqrt(norm());
}
bool operator<(const Point& p) const {
return x != p.x ? x < p.x : y < p.y;
}
bool operator==(const Point& p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
// ベクトルを表す構造体
typedef Point Vector;
// ベクトルのノルムを計算する
int norm(Vector a) {
return a.x * a.x + a.y * a.y;
}
// ベクトル a とベクトル b の内積を求める
int dot(Vector a, Vector b) {
return a.x * b.x + a.y * b.y;
}
int main() {
int x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Point p1 = Point(x1, y1), p2 = Point(x2, y2),
p3 = Point(x3, y3);
Vector v1 = p2 - p1, v2 = p3 - p1, v3 = v2 - v1, v4 = v1 - v2;
Point p4;
if (dot(v1, v2) == 0 && norm(v1) == norm(v2)) {
p4 = v1 + v2;
cout << p4.x << " " << p4.y << endl;
} else if (dot(v1, v3) == 0 && norm(v1) == norm(v3)) {
p4 = p1 + v3;
cout << p4.x << " " << p4.y << endl;
} else if (dot(v2, v4) == 0 && norm(v2) == norm(v4)) {
p4 = p1 + v4;
cout << p4.x << " " << p4.y << endl;
} else {
cout << -1 << endl;
}
return 0;
}
ふーらくたる