結果

問題 No.132 点と平面との距離
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-08-26 15:30:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,905 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 79,648 KB
最終ジャッジ日時 2024-04-25 17:00:44
合計ジャッジ時間 11,701 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 603 ms
78,168 KB
testcase_01 AC 3,774 ms
79,648 KB
testcase_02 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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()
0