結果

問題 No.132 点と平面との距離
ユーザー te-shte-sh
提出日時 2017-01-31 14:24:35
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 647 ms / 5,000 ms
コード長 1,225 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 157,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 01:10:44
合計ジャッジ時間 3,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,384 KB
testcase_01 AC 192 ms
4,384 KB
testcase_02 AC 647 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
0