結果

問題 No.132 点と平面との距離
ユーザー codershifthcodershifth
提出日時 2015-08-15 00:07:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,782 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 148,528 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 11:51:58
合計ジャッジ時間 1,793 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;

struct Pt3d {
    double x,y,z;
    Pt3d(double a, double b, double c) : x(a), y(b), z(c) {}
    Pt3d operator+(const Pt3d &other) const { return Pt3d(x+other.x, y+other.y, z+other.z); }
    Pt3d operator-(const Pt3d &other) const { return Pt3d(x-other.x, y-other.y, z-other.z); }
};
Pt3d cross(const Pt3d &a, const Pt3d &b) {
        return Pt3d(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);
}
double dot(const Pt3d &a, const Pt3d &b) {
        return a.x*b.x+a.y*b.y+a.z*b.z;
}
double norm(const Pt3d &a) { return sqrt(dot(a,a)); }

class DistanceOfPointAndPlane {
public:
    void solve(void) {
            int N;
            cin>>N;

            double x,y,z;
            double dist = 0;

            cin>>x>>y>>z;
            Pt3d p0(x,y,z);
            vector<Pt3d> qs;
            REP(i,N)
            {
                cin>>x>>y>>z;
                qs.emplace_back(x,y,z);
            }

            REP(i,N)
            FOR(j,i+1,N)
            FOR(k,j+1,N)
            {
                auto p = qs[i];
                auto n = cross(qs[j]-qs[i], qs[k]-qs[i]);
                //
                // plane(x,y,z) = n.x*(x-p.x) + n.y*(y-p.y) + n.z*(z-p.z) = 0
                // |plane(x0,y0,z0)|/norm(n);
                //
                dist += abs(dot(n,p0-p))/norm(n);
            }
            cout<<setprecision(20)<<dist<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new DistanceOfPointAndPlane();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0