結果

問題 No.132 点と平面との距離
ユーザー tottoripapertottoripaper
提出日時 2019-03-09 16:20:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 1,634 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 166,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:49:53
合計ジャッジ時間 1,905 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;

struct Point{
    double x, y, z;
    
    Point() = default;
    Point(double x, double y, double z) : x(x), y(y), z(z) {}

    double abs(){
        return std::sqrt(x * x + y * y + z * z);
    }

    Point& operator+=(Point &rhs){
        x += rhs.x; y += rhs.y; z += rhs.z;
        return *this;
    }

    friend Point operator+(Point lhs, Point &rhs){return lhs += rhs;}

    Point& operator-=(Point &rhs){
        x -= rhs.x; y -= rhs.y; z -= rhs.z;
        return *this;
    }

    friend Point operator-(Point lhs, Point &rhs){return lhs -= rhs;}

    friend std::istream& operator>>(std::istream &is, Point &p){return is >> p.x >> p.y >> p.z;}
};

Point cross(Point p, Point q){
    return {p.y * q.z - p.z * q.y, -(p.x * q.z - p.z * q.x), p.x * q.y - p.y * q.x};
}

double dot(Point p, Point q){
    return p.x * q.x + p.y * q.y + p.z * q.z;
}

int N;
Point p, qs[300];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    std::cin >> p;

    for(int i=0;i<N;++i){
        std::cin >> qs[i];
    }

    double sum = 0;

    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            for(int k=j+1;k<N;++k){
                Point n = cross(qs[j] - qs[i], qs[k] - qs[i]);
                double d = dot(qs[i], n);
                double dist = std::abs(dot(p, n) - d) / n.abs();
                sum += dist;
            }
        }
    }

    printf("%.10f\n", sum);
}
0