結果

問題 No.132 点と平面との距離
ユーザー koyoprokoyopro
提出日時 2020-01-04 23:18:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 2,213 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 146,248 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-14 20:51:31
合計ジャッジ時間 1,761 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

int N,M,L;

template<typename T> struct Pos {
    T x, y, z;
    Pos(){};
    Pos(T _x, T _y): x(_x), y(_y){};
    Pos(T _x, T _y, T _z): x(_x), y(_y), z(_z){};
    
    Pos operator * (T t) {
        return Pos(t * x, t * y);
    }
    Pos operator + (Pos q) {
        return Pos(x + q.x, y + q.y, z + q.z);
    }
    Pos operator - (Pos q) {
        return Pos(x - q.x, y - q.y, z - q.z);
    }
    int dot(Pos q) {
        return x * q.x + y * q.y;
    }
    int det(Pos q) {
        return x * q.y - y * q.x;
    }
    bool operator == (Pos q) {
        return (x == q.x) && (y == q.y);
    }
    Pos operator * ( const Pos& q ) {
        return Pos( y*q.z - z*q.y ,
                       z*q.x - x*q.z ,
                       x*q.y - y*q.x );
    }
    double operator % ( const Pos& q ) {
        return ( x*q.x + y*q.y + z*q.z );
    }
    double norm() {
        return sqrt(x*x + y*y + z*z);
    }
};

typedef Pos<double> pos;
pos p;
vector<pos> X(444);

double dist(int i, int j, int k) {
    pos a = X[i], b = X[j], c = X[k];
    pos pa =a-p, pb=b-p, pc=c-p;
    double v = (pa.y*pb.z*pc.x + pa.z*pb.x*pc.y + pa.x*pb.y*pc.z - pa.z*pb.y*pc.x - pa.x*pb.z*pc.y - pa.y*pb.x*pc.z)/6;
    double s = ((b-a)*(c-a)).norm()/2;
    return abs(3*v/s);
}

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N;
    cin>>p.x>>p.y>>p.z;
    REP(i,N)cin>>X[i].x>>X[i].y>>X[i].z;
    
    double ans = 0;
    
    FOR(i,0,N-2) FOR(j,i+1,N-1) FOR(k,j+1,N) {
        ans += dist(i,j,k);
    }
    
    out("%.14f\n", ans);
    
    return 0;
}
0