結果

問題 No.132 点と平面との距離
ユーザー te-shte-sh
提出日時 2016-09-07 10:09:05
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 416 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 165,424 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:57:35
合計ジャッジ時間 3,247 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

struct point {
  real x, y, z;
}

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = iota(n + 1)
    .map!(_ => readln.split.map!(to!real))
    .map!(rd => point(rd[0], rd[1], rd[2])).array;
  auto p = ai.front;
  auto qi = ai[1..$];

  auto bi = new bool[](n);
  bi[3..$] = true;

  real s = 0;
  foreach (i; 0..n - 2)
    foreach (j; i + 1..n - 1)
      foreach (k; j + 1..n)
        s += calc(p, qi[i], qi[j], qi[k]);

  writefln("%.9f", s);
}

real calc(point p, point a, point b, point c)
{
  auto d = (b.y - a.y) * (c.z - a.z) - (c.y - a.y) * (b.z - a.z);
  auto e = (b.z - a.z) * (c.x - a.x) - (c.z - a.z) * (b.x - a.x);
  auto f = (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
  auto g = -(d * a.x + e * a.y + f * a.z);

  return (d * p.x + e * p.y + f * p.z + g).abs / (d ^^ 2 + e ^^ 2 + f ^^ 2).sqrt;
}
0