結果

問題 No.132 点と平面との距離
ユーザー ttkkggwwttkkggww
提出日時 2022-05-10 22:24:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 1,311 bytes
コンパイル時間 4,257 ms
コンパイル使用メモリ 267,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 06:17:08
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n;
using TUP = tuple<double,double,double>;
TUP p;
vector<TUP> q;

double dist(TUP p,double a,double b,double c,double d){
	auto &[x,y,z] = p;
	return abs(a*x+b*y+c*z+d)/sqrt(a*a+b*b+c*c);
}

tuple<double,double,double,double> convert(TUP a,TUP b,TUP c){
	tuple<double,double,double,double> res;
	TUP ab,ac;
	{
		auto [a1,a2,a3] = a;
		auto [b1,b2,b3] = b;
		ab = TUP(b1-a1,b2-a2,b3-a3);
	}
	{
		auto [a1,a2,a3] = a;
		auto [c1,c2,c3] = c;
		ac = TUP(c1-a1,c2-a2,c3-a3);
	}
	{
		auto [a1,a2,a3] = ab;
		auto [b1,b2,b3] = ac;

		auto &[r1,r2,r3,r4] = res;
		r1 = a2*b3-a3*b2;
		r2 = a3*b1-a1*b3;
		r3 = a1*b2-b1*a2;
		{
			auto [a1,a2,a3] = a;
			r4 = -(a1*r1+a2*r2+a3*r3);
		}
	}
	return res;
}

void solve(){
	double ans = 0;
	for(int i = 0;i<n;i++){
		for(int j = i+1;j<n;j++){
			for(int k = j+1;k<n;k++){
				auto heimen = convert(q[i],q[j],q[k]);
				auto &[a,b,c,d] = heimen;
				//cerr<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
				ans += dist(p,a,b,c,d);
			}
		}
	}
	printf("%.10lf\n",ans);
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	{
		auto &[x,y,z] = p;
		cin >> x >> y >> z;
	}
	q = vector<TUP>(n);
	for(auto &[x,y,z]:q)cin >> x >> y >> z;
	solve();
}
0