結果

問題 No.132 点と平面との距離
ユーザー kaffelunkaffelun
提出日時 2018-10-16 00:03:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,259 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 147,720 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 20:26:00
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct Vector3 {
	T x,y,z;
	Vector3 operator+(const Vector3 &v) {
		return { x + v.x, y + v.y, z + v.z };
	}
	Vector3 operator-(const Vector3 &v) {
		return { x - v.x, y - v.y, z - v.z };
	}
	T dot(const Vector3 &v) {
		return  x * v.x + y * v.y + z * v.z;
	}
	Vector3 cross(Vector3 v) {
		return {
			y * v.z - z * v.y,
			z * v.x - x * v.z,
			x * v.y - y * v.x
		};
	}
	T abs() {
        return sqrt(x * x + y * y + z * z);
    }
};
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    Vector3<double> P;
    vector<Vector3<double>> V(N);
    cin >> P.x >> P.y >> P.z;
    for(int i = 0; i < N; i++) {
        cin >> V[i].x >> V[i].y >> V[i].z;
    }
    double ans = 0;
    // O(N^3)
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            Vector3<double> v1 = V[j] - V[i];
            for(int k = j + 1; k < N; k++) {
                Vector3<double> norm = v1.cross(V[k] - V[i]);
                ans += abs(norm.dot(P) - norm.dot(V[i])) / norm.abs();
            }
        }
    }
    cout << std::fixed << std::setprecision(15) << ans << endl;
    return 0;
}
0