結果

問題 No.132 点と平面との距離
ユーザー otsnskotsnsk
提出日時 2015-01-22 23:48:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,775 bytes
コンパイル時間 2,770 ms
コンパイル使用メモリ 70,300 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 03:53:18
合計ジャッジ時間 2,300 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

struct Vector3D {
    double x, y, z;

    Vector3D(){}
    Vector3D(double x, double y, double z): x(x), y(y), z(z) {}
    Vector3D(const Vector3D &v) {
        x = v.x; y = v.y; z = v.z;
    }

    Vector3D operator+(const Vector3D &v) const {
        return Vector3D(x+v.x, y+v.y, z+v.z);
    }
    Vector3D operator-(const Vector3D &v) const {
        return Vector3D(x-v.x, y-v.y, z-v.z);
    }

    double length() { return sqrt(x*x+y*y+z*z); }
    void normalize() {
        double l = length();
        x/=l; y/=l; z/=l;
    }

    double dot(const Vector3D &v) {
        return x*v.x + y*v.y + z*v.z;
    }

    Vector3D cross(const Vector3D &v) {
        return Vector3D(y * v.z - z * v.y,
                        z * v.x - x * v.z,
                        x * v.y - y * v.x);
    }
};


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

    int N;
    cin >> N;
    Vector3D p;
    vector<Vector3D> v(N);
    cin >> p.x >> p.y >> p.z;
    FOR(i, N) cin >> v[i].x >> v[i].y >> v[i].z;

    Vector3D vp, v1, v2, normal;
    double length = 0;
    v1 = v[1] - v[0];
    FOR(i, N) FOR(j, i) {
        vp = v[i] - p;
        v1 = v[j] - v[i];
        FOR(k, j) {
            v2 = v[k] - v[j];
            normal = v1.cross(v2);
            normal.normalize();
            length += abs(vp.dot(normal));
        }
    }

    cout << fixed << setprecision(10);
    cout << length << endl;
    
    return 0;
}
0