結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
![]() |
提出日時 | 2016-08-10 22:55:27 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,925 bytes |
コンパイル時間 | 516 ms |
コンパイル使用メモリ | 69,252 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 13:55:25 |
合計ジャッジ時間 | 1,292 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#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 = p1 + 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;}