結果

問題 No.132 点と平面との距離
ユーザー masamasa
提出日時 2015-01-21 01:08:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,333 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 67,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 02:41:51
合計ジャッジ時間 1,156 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

typedef struct {
	double x;
	double y;
	double z;
} Point;


Point subtract(Point, Point);;
Point cross_product(Point, Point);
double calc(Point, Point, Point);

Point p;

int main() {
	int n;

	cin >> n;

	int x, y, z;
	vector<Point> q(n);

	cin >> p.x >> p.y >> p.z;
	for (int i = 0; i < n; i++) {
		cin >> q[i].x >> q[i].y >> q[i].z;
	}

	Point ab, ac;

	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 += calc(q[i], q[j], q[k]);
			}
		}
	}

	printf("%.10f\n", ans);
	return 0;
}

Point subtract(Point a, Point b) {
	Point c;
	c.x = a.x - b.x;
	c.y = a.y - b.y;
	c.z = a.z - b.z;

	return c;
}

Point cross_product(Point a, Point b) {
	Point c;
	c.x = a.y * b.z - a.z * b.y;
	c.y = a.z * b.x - a.x * b.z;
	c.z = a.x * b.y - a.y * b.x;
	return c;
}

double calc(Point p1, Point p2, Point p3) {
	Point p12, p13, cross;

	p12 = subtract(p2, p1);
	p13 = subtract(p3, p1);

	cross = cross_product(p12, p13);

	double d;
	d = -1.0 *(cross.x * p1.x + cross.y * p1.y + cross.z * p1.z);

	return abs(cross.x * p.x + cross.y * p.y + cross.z * p.z + d) / sqrt(cross.x * cross.x + cross.y * cross.y + cross.z * cross.z);
}
0