結果
| 問題 | No.132 点と平面との距離 | 
| コンテスト | |
| ユーザー |  norioc | 
| 提出日時 | 2019-10-29 02:08:55 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 353 ms / 5,000 ms | 
| コード長 | 2,267 bytes | 
| コンパイル時間 | 3,260 ms | 
| コンパイル使用メモリ | 219,332 KB | 
| 実行使用メモリ | 6,940 KB | 
| 最終ジャッジ日時 | 2024-06-22 02:58:54 | 
| 合計ジャッジ時間 | 3,584 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 | 
ソースコード
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); }
}
            
            
            
        