結果

問題 No.132 点と平面との距離
ユーザー SSRSSSRS
提出日時 2020-11-21 12:54:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 1,251 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 79,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 21:45:35
合計ジャッジ時間 1,366 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
struct point{
	double x, y, z;
	point(){
	}
	point(double x, double y, double z): x(x), y(y), z(z){
	}
	point operator -(point P){
		return point(x - P.x, y - P.y, z - P.z);
	}
};
double abs(point P){
	return sqrt(P.x * P.x + P.y * P.y + P.z * P.z);
}
double dot(point P, point Q){
	return P.x * Q.x + P.y * Q.y + P.z * Q.z;
}
point cross(point P, point Q){
	return point(P.y * Q.z - Q.y * P.z, P.z * Q.x - Q.z * P.x, P.x * Q.y - Q.x * P.y);
}
double volume(point P, point Q, point R){
	return abs(dot(cross(P, Q), R));
}
struct plane{
	point A, B, C;
	plane(point A, point B, point C): A(A), B(B), C(C){
	}
};
double point_plane_distance(point P, plane T){
	return abs(volume(P - T.A, T.B - T.A, T.C - T.A)) / abs(cross(T.B - T.A, T.C - T.A));
}
int main(){
	cout << fixed << setprecision(15);
	int N;
	cin >> N;
	point P;
	cin >> P.x >> P.y >> P.z;
	vector<point> Q(N);
	for (int i = 0; i < N; i++){
		cin >> Q[i].x >> Q[i].y >> Q[i].z;
	}
	double ans = 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 += point_plane_distance(P, plane(Q[i], Q[j], Q[k]));
			}
		}
	}
	cout << ans << endl;
}
0