結果

問題 No.132 点と平面との距離
ユーザー tubo28tubo28
提出日時 2015-01-20 23:45:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 1,827 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 152,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 02:33:03
合計ジャッジ時間 1,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

typedef long double R;
typedef tuple<R,R,R> P;

#define PCR P const&

P cross(PCR a, PCR b){
    R a1,a2,a3;
    R b1,b2,b3;
    tie(a1,a2,a3) = a;
    tie(b1,b2,b3) = b;
    return mt(a2*b3-a3*b2, a3*b1-a1*b3, a1*b2-a2*b1);
}

P operator-(PCR a, PCR b){
    R a1,a2,a3;
    R b1,b2,b3;
    tie(a1,a2,a3) = a;
    tie(b1,b2,b3) = b;
    return P(a1-b1, a2-b2, a3-b3);
}

P p;
P ps[400];

R dist(int i, int j, int k){
    R v1,v2,v3;
    tie(v1,v2,v3) = cross(ps[i]-ps[k],ps[j]-ps[k]);
    R a1,a2,a3;
    tie(a1,a2,a3) = ps[k];
    R d = v1*a1 + v2*a2 + v3*a3;
    R x,y,z;
    tie(x,y,z) = p;
    return abs(v1*x + v2*y + v3*z - d) / sqrt(v1*v1 + v2*v2 + v3*v3);
}

int main(){
    int N;
    while(cin>>N){
        R x,y,z;
        cin >> x >> y >> z;
        p = P(x,y,z);
        rep(i,N){
            cin >> x >> y >> z;
            ps[i] = P(x,y,z);
        }
        R ans = 0;
        rep(i,N)rep(j,i)rep(k,j) ans += dist(i,j,k);
        printf("%.20lf\n", (double)ans);
    }
}
0