結果

問題 No.132 点と平面との距離
ユーザー ctyl_0ctyl_0
提出日時 2015-11-11 17:22:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 2,666 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 88,248 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 15:39:25
合計ジャッジ時間 1,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0