結果

問題 No.132 点と平面との距離
コンテスト
ユーザー はむ吉🐹
提出日時 2016-08-26 15:57:19
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 3,202 ms / 5,000 ms
コード長 1,517 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 385 ms
コンパイル使用メモリ 85,200 KB
実行使用メモリ 82,820 KB
最終ジャッジ日時 2026-05-08 11:10:37
合計ジャッジ時間 5,536 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/env pypy3

import collections
import itertools
import math


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
        m1 = self.y * other.z - self.z * other.y
        m2 = self.z * other.x - self.x * other.z
        m3 = self.x * other.y - self.y * other.x
        return Vector3(m1, m2, m3)

    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 dist(q1, q2, q3):
    v1 = q2 - q1
    v2 = q3 - q2
    cp = v1 * v2
    return abs(q1.dotproduct(cp)) / abs(cp)


def solve(p, qs):
    return sum(dist(*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())) - p for _ in range(n)]
    print("{:.12f}".format(solve(p, qs)))


if __name__ == '__main__':
    main()
0