結果

問題 No.622 点と三角柱の内外判定
ユーザー 👑 obakyanobakyan
提出日時 2019-05-09 23:57:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 17:48:09
合計ジャッジ時間 2,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local x, y, z = {}, {}, {}
for i = 1, 4 do
  x[i], y[i], z[i] = io.read("*n", "*n", "*n")
end
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]
x[4] = x[4] - innerpr * e3[1]
y[4] = y[4] - innerpr * e3[2]
z[4] = z[4] - innerpr * e3[3]

--[[
s(x2,y2,z2) + t(x3,y3,z3) = (x,y,z)
x2 x3  s = x
y2 y3  t   y
]]
local epsilon = 1.0e-5
local s, t = 0, 0
local det = x[2] * y[3] - x[3] * y[2]
if epsilon < math.abs(det) then
  s, t = (x[4] * y[3] - y[4] * x[3]) / det, (-x[4] * y[2] + y[4] * x[2]) / det
else
  det = x[2] * z[3] - x[3] * z[2]
  s, t = (x[4] * z[3] - z[4] * x[3]) / det, (-x[4] * z[2] + z[4] * x[2]) / det
end
if(0 <= s + t and s + t <= 1) then print("YES") else print("NO") end
0