結果

問題 No.132 点と平面との距離
ユーザー noriocnorioc
提出日時 2019-10-29 02:08:55
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 361 ms / 5,000 ms
コード長 2,267 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 213,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 03:16:19
合計ジャッジ時間 3,460 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

double calc(Vec3 p, Vec3[] vs) {
    double sum = 0;

    for (int i = 0; i < vs.length; i++) {
        for (int j = i + 1; j < vs.length; j++) {
            for (int k = j + 1; k < vs.length; k++) {
                auto ab = vs[j] - vs[i];
                auto ac = vs[k] - vs[i];

                auto v = ab.cross(ac).normalized();
                auto ap = p - vs[i];
                sum += abs(ap.dot(v));
            }
        }
    }
    return sum;
}

void main() {
    int n = readint;
    double px, py, pz; scan(px, py, pz);
    auto p = Vec3(px, py, pz);
    Vec3[] vs;
    for (int i = 0; i < n; i++) {
        double x, y, z; scan(x, y, z);
        vs ~= Vec3(x, y, z);
    }

    auto ans = calc(p, vs);
    writefln("%.8f", ans);
}

struct Vec3 {
    immutable double x;
    immutable double y;
    immutable double z;

    this(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    double dot(Vec3 o) {
        return this.x * o.x + this.y * o.y + this.z * o.z;
    }

    Vec3 cross(Vec3 o) {
        auto x = this.y * o.z - o.y * this.z;
        auto y = this.z * o.x - o.z * this.x;
        auto z = this.x * o.y - o.x * this.y;
        return Vec3(x, y, z);
    }

    double mag() { return sqrt(magSq()); }
    double magSq() { return this.x * this.x + this.y * this.y + this.z * this.z; }

    Vec3 normalized() {
        auto m = mag();
        return Vec3(this.x / m, this.y / m, this.z / m);
    }

    Vec3 opUnary(string op)() if (op == "-") { return Vec3(-this.x, -this.y, -this.z); }
    Vec3 opBinary(string op)(Vec3 o) if (op == "+") { return Vec3(this.x + o.x, this.y + o.y, this.z + o.z); }
    Vec3 opBinary(string op)(Vec3 o) if (op == "-") { return Vec3(this.x - o.x, this.y - o.y, this.z - o.z); }
    Vec3 opBinary(string op)(double d) if (op == "*") { return Vec3(this.x * d, this.y * d, this.z * d); }
    Vec3 opBinaryRight(string op)(double d) if (op == "*") { return Vec3(this.x * d, this.y * d, this.z * d); }
}
0