結果
| 問題 | No.132 点と平面との距離 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-11 17:22:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 102 ms / 5,000 ms |
| コード長 | 2,666 bytes |
| 記録 | |
| コンパイル時間 | 677 ms |
| コンパイル使用メモリ | 88,592 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 14:26:21 |
| 合計ジャッジ時間 | 1,292 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
}
template <typename T>
void output(T a, int precision) {
if(precision > 0){
cout << fixed << setprecision(precision) << a << "\n";
}
else{
cout << a << "\n";
}
}
class vec3 {
public:
double x;
double y;
double z;
vec3(){
}
vec3(double x, double y, double z){
this -> x = x;
this -> y = y;
this -> z = z;
}
vec3 & operator += (const vec3 &a) {
this -> x += a.x;
this -> y += a.y;
this -> z += a.z;
return *this;
}
vec3 & operator -= (const vec3 &a) {
this -> x -= a.x;
this -> y -= a.y;
this -> z -= a.z;
return *this;
}
vec3 operator + (const vec3 &a) const {
vec3 ret = *this;
ret += a;
return ret;
}
vec3 operator - (const vec3 &a) const {
vec3 ret = *this;
ret -= a;
return ret;
}
};
double length(vec3 a, vec3 b){
double ret = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
return sqrt(ret);
}
double det(vec3 a, vec3 b, vec3 c){
return abs(a.x * b.y * c.z + a.y * b.z * c.x + a.z * b.x * c.y - a.x * b.z * c.y - a.y * b.x * c.z - a.z * b.y * c.x);
}
// end of template
double dist(vec3 x0, vec3 x1, vec3 x2, vec3 x3){
double a = length(x0, x1);
double b = length(x1, x2);
double c = length(x2, x0);
x1 -= x0;
x2 -= x0;
x3 -= x0;
// volume of tetrahedral * 6 = det(x1, x2, x3)
double d = det(x1, x2, x3);
// output(d, 10);
// area of bottom triangle
double s = (a + b + c) / 2;
double area = sqrt(s * (s - a) * (s - b) * (s - c));
// output(area, 10);
return d / (2 * area);
}
int main() {
cin.tie(0);
// source code
int N = inputValue();
vec3 p;
cin >> p.x >> p.y >> p.z;
vector<vec3> q(N);
rep(i, N){
cin >> q[i].x >> q[i].y >> q[i].z;
}
double ret = 0;
rep(i, N) repd(j, i + 1, N) repd(k, j + 1, N){
ret += dist(q[i], q[j], q[k], p);
}
output(ret, 10);
return 0;
}