結果

問題 No.132 点と平面との距離
ユーザー 👑 obakyanobakyan
提出日時 2019-05-10 20:24:54
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 3,906 ms / 5,000 ms
コード長 1,489 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 5,208 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 17:57:52
合計ジャッジ時間 6,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

local ior = io.input()
local n = ior:read("*n")
local px, py, pz = ior:read("*n", "*n", "*n")
local tx, ty, tz = {}, {}, {}
for i = 1, n do
  tx[i], ty[i], tz[i] = ior:read("*n", "*n", "*n")
end

local function getlen(idxs)
  local x, y, z = {}, {}, {}
  for i = 1, 3 do
    x[i], y[i], z[i] = tx[idxs[i]], ty[idxs[i]], tz[idxs[i]]
  end
  x[4], y[4], z[4] = px, py, pz
  for i = 2, 4 do
    x[i], y[i], z[i] = x[i] - x[1], y[i] - y[1], z[i] - z[1]
  end
  local e1sz = math.sqrt(x[2] * x[2] + y[2] * y[2] + z[2] * z[2])
  local e1 = {x[2] / e1sz, y[2] / e1sz, z[2] / e1sz}

  local innerpr = e1[1] * x[3] + e1[2] * y[3] + e1[3] * z[3]
  local e2 = {
    x[3] - innerpr * e1[1],
    y[3] - innerpr * e1[2],
    z[3] - innerpr * e1[3]
    }
  local e2sz = math.sqrt(e2[1] * e2[1] + e2[2] * e2[2] + e2[3] * e2[3])
  for i = 1, 3 do e2[i] = e2[i] / e2sz end

  local e3 = {x[4], y[4], z[4]}
  innerpr = e3[1] * e1[1] + e3[2] * e1[2] + e3[3] * e1[3]
  for i = 1, 3 do
    e3[i] = e3[i] - e1[i] * innerpr
  end
  innerpr = e3[1] * e2[1] + e3[2] * e2[2] + e3[3] * e2[3]
  for i = 1, 3 do
    e3[i] = e3[i] - e2[i] * innerpr
  end
  local e3sz = math.sqrt(e3[1] * e3[1] + e3[2] * e3[2] + e3[3] * e3[3])
  for i = 1, 3 do e3[i] = e3[i] / e3sz end
  innerpr = e3[1] * x[4] + e3[2] * y[4] + e3[3] * z[4]
  return innerpr
end

local sum = 0
for i = 1, n - 2 do
  for j = i + 1, n - 1 do
    for k = j + 1, n do
      sum = sum + getlen({i, j, k})
    end
  end
end
print(string.format("%.10f", sum))
0