結果
| 問題 |
No.132 点と平面との距離
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-08-26 15:30:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,905 bytes |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 85,708 KB |
| 最終ジャッジ日時 | 2024-11-08 04:10:20 |
| 合計ジャッジ時間 | 12,307 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 |
ソースコード
#!/usr/bin/env pypy3
import collections
import itertools
import math
def det3(a):
d = a[0][0] * a[1][1] * a[2][2] + a[0][1] * a[1][2] * a[2][0]
d += a[0][2] * a[1][0] * a[2][1] - a[0][0] * a[1][2] * a[2][1]
d -= a[0][1] * a[1][0] * a[2][2] + a[0][2] * a[1][1] * a[2][0]
return d
class Vector3(collections.namedtuple("Vector3", "x y z")):
__slots__ = ()
def __add__(self, other):
return Vector3(*(s + o for s, o in zip(self, other)))
def __sub__(self, other):
return Vector3(*(s - o for s, o in zip(self, other)))
def __mul__(self, other): # cross product
return abs(self) * abs(other) * math.sin(self.angle(other))
def __neg__(self):
return Vector3(-self.x, -self.y, -self.z)
def __pos__(self):
return Vector3(+self.x, +self.y, +self.z)
def __abs__(self): # norm
return math.sqrt(sum(s * s for s in self))
def dotproduct(self, other):
return sum(s * o for s, o in zip(self, other))
def angle(self, other):
return math.acos(self.dotproduct(other) / abs(self) / abs(other))
def scale(self, k):
return Vector3(k * self.x, k * self.y, k * self.z)
def volume_of_trigonal_pyramid(p, q1, q2, q3):
v1 = q1 - p
v2 = q2 - p
v3 = q3 - p
a = [list(v1), list(v2), list(v3)]
return abs(det3(a) / 6)
def volume_of_triangle(q1, q2, q3):
a = q2 - q1
b = q3 - q1
return abs(a * b) / 2
def dist(p, q1, q2, q3):
d = volume_of_trigonal_pyramid(p, q1, q2, q3) * 3
d /= volume_of_triangle(q1, q2, q3)
return d
def solve(p, qs):
return sum(dist(p, *q123) for q123 in itertools.combinations(qs, 3))
def main():
n = int(input())
p = Vector3(*map(float, input().split()))
qs = [Vector3(*map(float, input().split())) for _ in range(n)]
print("{:.12f}".format(solve(p, qs)))
if __name__ == '__main__':
main()
はむ吉🐹