結果
問題 | No.132 点と平面との距離 |
ユーザー |
![]() |
提出日時 | 2015-08-15 00:07:42 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 27 ms / 5,000 ms |
コード長 | 1,782 bytes |
コンパイル時間 | 1,174 ms |
コンパイル使用メモリ | 163,092 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 09:32:14 |
合計ジャッジ時間 | 1,552 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>typedef long long ll;typedef unsigned long long ull;#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)#define REP(i,n) FOR(i,0,n)#define RANGE(vec) (vec).begin(),(vec).end()using namespace std;struct Pt3d {double x,y,z;Pt3d(double a, double b, double c) : x(a), y(b), z(c) {}Pt3d operator+(const Pt3d &other) const { return Pt3d(x+other.x, y+other.y, z+other.z); }Pt3d operator-(const Pt3d &other) const { return Pt3d(x-other.x, y-other.y, z-other.z); }};Pt3d cross(const Pt3d &a, const Pt3d &b) {return Pt3d(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);}double dot(const Pt3d &a, const Pt3d &b) {return a.x*b.x+a.y*b.y+a.z*b.z;}double norm(const Pt3d &a) { return sqrt(dot(a,a)); }class DistanceOfPointAndPlane {public:void solve(void) {int N;cin>>N;double x,y,z;double dist = 0;cin>>x>>y>>z;Pt3d p0(x,y,z);vector<Pt3d> qs;REP(i,N){cin>>x>>y>>z;qs.emplace_back(x,y,z);}REP(i,N)FOR(j,i+1,N)FOR(k,j+1,N){auto p = qs[i];auto n = cross(qs[j]-qs[i], qs[k]-qs[i]);//// plane(x,y,z) = n.x*(x-p.x) + n.y*(y-p.y) + n.z*(z-p.z) = 0// |plane(x0,y0,z0)|/norm(n);//dist += abs(dot(n,p0-p))/norm(n);}cout<<setprecision(20)<<dist<<endl;}};#if 1int main(int argc, char *argv[]){ios::sync_with_stdio(false);auto obj = new DistanceOfPointAndPlane();obj->solve();delete obj;return 0;}#endif