結果
| 問題 |
No.55 正方形を描くだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2018-06-30 13:55:58 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,786 bytes |
| コンパイル時間 | 448 ms |
| コンパイル使用メモリ | 99,520 KB |
| 最終ジャッジ日時 | 2024-11-14 20:31:54 |
| 合計ジャッジ時間 | 843 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.d(17): Error: `opSub` is obsolete. Use `opBinary(string op)(...) if (op == "-")` instead. Main.d(18): Error: `opSub` is obsolete. Use `opBinary(string op)(...) if (op == "-")` instead. Main.d(83): Error: `opSub` is obsolete. Use `opBinary(string op)(...) if (op == "-")` instead.
ソースコード
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void calc(Vec2 a, Vec2 b, Vec2 c) {
foreach (s; [[a, b, c], [b, a, c], [c, a, b]]) {
auto ab = s[1] - s[0];
auto ac = s[2] - s[0];
if (ab.dot(ac) == 0 && ab.magSq == ac.magSq) {
auto ad = ab + ac;
auto d = ad + s[0];
writeln(d.x, " ", d.y);
return;
}
}
writeln(-1); // not found
}
void main() {
auto xs = readints;
auto a = Vec2(xs[0], xs[1]);
auto b = Vec2(xs[2], xs[3]);
auto c = Vec2(xs[4], xs[5]);
calc(a, b, c);
}
struct Vec2 {
immutable double x;
immutable double y;
this(double x, double y) {
this.x = x;
this.y = y;
}
Vec2 opAdd(Vec2 other) {
return Vec2(this.x + other.x, this.y + other.y);
}
Vec2 opSub(Vec2 other) {
return Vec2(this.x - other.x, this.y - other.y);
}
Vec2 opMul(double d) {
return Vec2(this.x * d, this.y * d);
}
double dot(Vec2 other) {
return this.x * other.x + this.y * other.y;
}
double cross(Vec2 other) {
return this.x * other.y - other.x * this.y;
}
double mag() {
return sqrt(magSq());
}
double magSq() {
return this.x * this.x + this.y * this.y;
}
Vec2 normalize() {
auto m = mag();
if (m != 0 && m != 1)
return Vec2(this.x / m, this.y / m);
return this;
}
static double distance(Vec2 a, Vec2 b) {
return (a - b).mag();
}
}
norioc