結果

問題 No.132 点と平面との距離
ユーザー 沙耶花沙耶花
提出日時 2021-10-27 23:00:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 3,621 bytes
コンパイル時間 4,393 ms
コンパイル使用メモリ 255,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:46:50
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

const double eps = 1e-10;

template <typename T>
struct vector_3d{
	T x,y,z;
	
	vector_3d(T a=0.0,T b=0.0,T c=0.0){
		x = a;
		y = b;
		z = c;
	}
	
	void update_x(T a,T b){
		x = a*x + b;
	}
	
	void update_x(T a){
		update_x(0.0,a);
	}
	
	void update_y(T a,T b){
		y = a*y + b;
	}
	
	void update_y(T a){
		update_y(0.0,a);
	}
	
	void update_z(T a,T b){
		z = a*z + b;
	}
	
	void update_z(T a){
		update_z(0.0,a);
	}
	
	void fix_zero(){
		if(abs(x)<eps)x = 0.0;
		if(abs(y)<eps)y = 0.0;
		if(abs(z)<eps)z = 0.0;
	}
	
	void normalize(){
		T s = size();
		update_x(1.0/s,0.0);
		update_y(1.0/s,0.0);
		update_z(1.0/s,0.0);
	}
	
	T get_dis(vector_3d<T> V){
		return sqrt(pow(x-V.x,2.0)+pow(y-V.y,2.0)+pow(z-V.z,2.0));
	}
	
	T size(){
		return get_dis(vector_3d<T>());
	}
	
	//中点
	vector_3d get_midpoint(vector_3d<T> V){
		V.update_x(0.5,x/2.0);
		V.update_y(0.5,y/2.0);
		V.update_z(0.5,y/2.0);
		return V;
	}
	
	
	T get_inner_product(vector_3d<T> V){
		return x*V.x+y*V.y+z*V.z;
	}
	
	T get_cross_product(vector_3d<T> V){
		return get_inner_product(this)*V.get_inner_product(V)-pow(get_inner_product(V),2.0);
	}
	
	vector_3d get_cross_product_vector(vector_3d<T> V){
		return vector_3d<T> (y*V.z-z*V.y, z*V.x-x*V.z, x*V.y-y*V.x);
	}
	
	vector_3d &operator+=(const vector_3d<T> &another){
		update_x(1,another.x);
		update_y(1,another.y);
		update_z(1,another.z);
		return (*this);
	}
	
	vector_3d &operator-=(const vector_3d<T> &another){
		update_x(1,-another.x);
		update_y(1,-another.y);
		update_z(1,-another.z);
		return (*this);
	}
	
	vector_3d operator+(const vector_3d<T> &another)const{
		return (vector_3d(*this)+=another);
	}
	
	vector_3d operator-(const vector_3d<T> &another)const{
		return (vector_3d(*this)-=another);
	}
	
	void show(){
		cout<<x<<','<<y<<','<<z<<endl;
	}
};

template <typename T>
struct line_3d{
	vector_3d<T> a,t;
	
	line_3d(vector_3d<T> V1,vector_3d<T> V2){
		a=V1;
		t=V2-V1;
	}


	T get_signed_dis(vector_3d<T> V){
		vector_3d<T> PA = a-V;
		return PA.get_cross_product(t)/t.size();
	}
	
	T get_dis(vector_3d<T> V){
		return abs(get_signed_dis(V));
	}

	vector_3d<T> get_projection(vector_3d<T> P){
		T r = t.get_inner_product(P-a)/t.size();
		vector_3d<T> temp = t;
		temp.normalize();
		temp.x*=r;
		temp.y*=r;
		temp.z*=r;
		return a+temp;
	}
	
	/*
	
	vector_3d<T> get_cross_point(line_3d<T> L){
		vector_3d<T> ret(1e20,1e20);

		if(abs(L.a*b-a*L.b)>=eps){
			ret.update_x((L.b*c-b*L.c)/(L.a*b-a*L.b));
			ret.update_y((a*L.c-L.a*c)/(L.a*b-a*L.b));
		}

		return ret;
	}
	*/

	
};

template <typename T>
struct plane{
	
	vector_3d<T> a,t0,t1;
	
	plane(vector_3d<T> V1,vector_3d<T> V2,vector_3d<T> V3){
		a = V1;
		t0 = V2-V1;
		t1 = V3-V2;
	}
	
	T get_signed_dis(vector_3d<T> V){
		vector_3d<T> PA = a-V;
		vector_3d<T> cp = t0.get_cross_product_vector(t1);
		cp.normalize();
		return cp.get_inner_product(PA);
	}
	
	T get_dis(vector_3d<T> V){
		return abs(get_signed_dis(V));
	}
	
	
};

int main(){
	
	int N;
	cin>>N;
	
	vector_3d<double> p;
	{
		double x,y,z;
		cin>>x>>y>>z;
		
		p = vector_3d<double>(x,y,z);
	}
	
	vector<vector_3d<double>> q(N);
	rep(i,N){
		double x,y,z;
		cin>>x>>y>>z;
		
		q[i] = vector_3d<double>(x,y,z);
	}
	
	double ans = 0.0;
	
	rep(i,N){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				plane<double> P(q[i],q[j],q[k]);
				ans += P.get_dis(p);
			}
		}
	}
	
	cout<<fixed<<setprecision(10)<<ans<<endl;
	
	return 0;
}
0