結果
| 問題 |
No.132 点と平面との距離
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-01-31 14:24:35 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 599 ms / 5,000 ms |
| コード長 | 1,225 bytes |
| コンパイル時間 | 2,615 ms |
| コンパイル使用メモリ | 157,352 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 06:47:25 |
| 合計ジャッジ時間 | 3,848 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math; // math functions
void main()
{
auto n = readln.chomp.to!size_t;
auto pr = readln.split.to!(real[]), p = point(pr[0], pr[1], pr[2]);
auto qi = n.iota
.map!(_ => readln.split.to!(real[]))
.map!(qr => point(qr[0], qr[1], qr[2]))
.map!(q => q - p)
.array;
auto r = real(0);
foreach (i; 0..n-2)
foreach (j; i+1..n-1)
foreach (k; j+1..n)
r += calc(qi[i], qi[j], qi[k]);
writefln("%.10f", r);
}
auto calc(point q1, point q2, point q3)
{
auto n = outerProd(q2 - q1, q3 - q1);
return (n * q1).abs / n.hypot2.sqrt;
}
struct Point3(T) {
T x, y, z;
auto opBinary(string op)(Point3!T rhs) {
static if (op == "+") return Point3!T(x + rhs.x, y + rhs.y, z + rhs.z);
else static if (op == "-") return Point3!T(x - rhs.x, y - rhs.y, z - rhs.z);
else static if (op == "*") return x * rhs.x + y * rhs.y + z * rhs.z;
}
T hypot2() { return x ^^ 2 + y ^^ 2 + z ^^ 2; }
}
auto outerProd(T)(Point3!T p1, Point3!T p2)
{
return Point3!T(p1.y * p2.z - p1.z * p2.y,
p1.z * p2.x - p1.x * p2.z,
p1.x * p2.y - p1.y * p2.x);
}
alias Point3!real point;