結果

問題 No.132 点と平面との距離
ユーザー parukiparuki
提出日時 2016-09-14 15:02:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 1,951 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 175,556 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-28 13:42:33
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define EPS 1e-10
struct V3{
    double x, y, z;
    V3(){}
    V3(double x_, double y_, double z_):x(x_),y(y_),z(z_){}
    V3 operator+(V3 p)const{
        return V3(x+p.x,y+p.y,z+p.z);
    }
    V3 operator-(V3 p)const{
        return V3(x-p.x,y-p.y,z-p.z);
    }
    double dist()const{
        return sqrt(x*x+y*y);
    }
};
V3 operator *(double k, V3 p){
    p.x *= k;
    p.y *= k;
    p.z *= k;
    return p;
}
double dot(const V3 &a, const V3 &b){
    return a.x*b.x + a.y*b.y + a.z*b.z;
}
V3 cross(const V3 &a, const V3 &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 V3(x, y, z);
}

tuple<double, double, double, double>
makePlane(const V3 &A, const V3 &B, const V3 &C){
    V3 AB = B - A, AC = C - A;
    V3 n = cross(AB, AC);
    double a=n.x, b=n.y, c=n.z, d;
    d = dot(n, (-1)*A);
    return make_tuple(a, b, c, d);
}

double distPointPlane(const V3 &P, tuple<double,double,double,double> l){
    double a, b, c, d, res;
    tie(a, b, c, d) = l;
    res = a*P.x + b*P.y + c*P.z + d;
    res /= hypot(a, hypot(b, c));
    return abs(res);
}

int main(){
    int N;
    V3 P;
    cin >> N >> P.x >> P.y >> P.z;
    vector<V3> Q(N);
    each(q, Q)cin >> q.x >> q.y >> q.z;
    double ans = 0;
    rep(k, N)rep(j, k)rep(i, j){
        auto l = makePlane(Q[i],Q[j],Q[k]);
        ans += distPointPlane(P, l);
    }
    cout << setprecision(20) << ans << endl;
}
0