結果

問題 No.132 点と平面との距離
ユーザー face4face4
提出日時 2019-03-02 15:59:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,149 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 80,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 16:55:16
合計ジャッジ時間 1,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
using namespace std;

struct Point{
    double x, y, z;
    Point operator-(Point o){
        return Point({this->x-o.x, this->y-o.y, this->z-o.z});
    }
    double size(){
        return sqrt(x*x + y*y + z*z);
    }
};

Point cross(Point a, Point b){
    double x, y, z;
    x = a.y*b.z-a.z*b.y;
    y = a.z*b.x-a.x*b.z;
    z = a.x*b.y-a.y*b.x;
    return Point({x, y, z});
}

int main(){
    int n;
    cin >> n;
    double x, y, z;
    cin >> x >> y >> z;
    Point p({x, y, z});
    vector<Point> v;
    for(int i = 0; i < n; i++){
        cin >> x >> y >> z;
        v.push_back(Point({x, y, z}));
    }
    double ans = 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 a = v[j]-v[i], b = v[k]-v[i];
                Point c = cross(a, b);
                double d = c.x*(-v[i].x) + c.y*(-v[i].y) + c.z*(-v[i].z);
                ans += abs(c.x*p.x + c.y*p.y + c.z*p.z + d) / c.size();
            }
        }
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}
0