結果
| 問題 |
No.132 点と平面との距離
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-21 01:23:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 5,000 ms |
| コード長 | 1,659 bytes |
| コンパイル時間 | 456 ms |
| コンパイル使用メモリ | 59,480 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-22 23:30:29 |
| 合計ジャッジ時間 | 871 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const int BUF = 305;
class Point{
public:
double x, y, z;
Point(){}
Point(double x, double y, double z):
x(x), y(y), z(z){}
Point operator- (const Point &opp) {
return Point(x - opp.x, y - opp.y, z - opp.z);
}
void normalize() {
double d = sqrt(x * x + y * y + z * z);
x /= d;
y /= d;
z /= d;
}
};
// 二つのベクトルの内積を取る
double dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
// 二つのベクトルの外積を取る
Point cross(const Point &a, const Point &b) {
return Point ((a.y * b.z) - (a.z * b.y),
(a.z * b.x) - (a.x * b.z),
(a.x * b.y) - (a.y * b.x));
}
int nPt;
Point P;
Point pt[BUF];
void read() {
cin >> nPt;
cin >> P.x >> P.y >> P.z;
for (int i = 0; i < nPt; ++i)
cin >> pt[i].x >> pt[i].y >> pt[i].z;
}
double calc(Point p, Point a, Point b, Point c) {
// abc の法線ベクトル n を求める
Point ab = b - a;
Point bc = c - b;
Point n = cross(ab, bc);
n.normalize();
// 平面上の任意の点として a をとり、 ベクトル pa と 法線ベクトル n の内積を取る
Point pa = a - p;
return fabs(dot(pa, n));
}
void work() {
double sum = 0;
for (int i = 0; i < nPt; ++i)
for (int j = i + 1; j < nPt; ++j)
for (int k = j + 1; k < nPt; ++k)
sum += calc(P, pt[i], pt[j], pt[k]);
printf("%.12lf\n", sum);
}
int main() {
read();
work();
return 0;
}