結果

問題 No.132 点と平面との距離
ユーザー finefine
提出日時 2017-02-27 23:30:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 1,081 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 13:33:16
合計ジャッジ時間 2,099 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct P {
	double x;
	double y;
	double z;
	P() : x(0), y(0), z(0) {}
	P(double x, double y, double z) : x(x), y(y), z(z) {}
	P operator-(const P& p) const {
		return P(x - p.x, y - p.y, z - p.z);
	}
};

int n;
P p;
vector<P> q;

P cross(P a, P b) {
	P res;
	res.x = a.y * b.z - a.z * b.y;
	res.y = a.z * b.x - a.x * b.z;
	res.z = a.x * b.y - a.y * b.x;
	return res;
}

double dist(int i, int j, int k) {
	P a = q[j] - q[i], b = q[k] - q[i];
	P c = cross(a, b);
	double d = -c.x * q[i].x - c.y * q[i].y - c.z * q[i].z;
	double res = abs(c.x * p.x + c.y * p.y + c.z * p.z + d);
	res /= sqrt(c.x * c.x + c.y * c.y + c.z * c.z);
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> p.x >> p.y >> p.z;
	q.resize(n);
	for (int i = 0; i < n; i++) cin >> q[i].x >> q[i].y >> q[i].z;
	double ans = 0.0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				ans += dist(i, j, k);
			}
		}
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}
0