結果

問題 No.132 点と平面との距離
ユーザー GoryudyumaGoryudyuma
提出日時 2015-06-18 22:23:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 3,345 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 128,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 09:34:30
合計ジャッジ時間 1,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

//#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
//#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
//#include <atomic>
#include <chrono>
//#include <condition_variable>
#include <forward_list>
//#include <future>
#include <initializer_list>
//#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
//#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


using namespace std;


class D3
{
public:
	double x;
	double y;
	double z;

	//コンストラクタ
	D3 ( double x_ = 0.0 , double y_ = 0.0 , double z_ = 0.0 )
	{
		x = x_;
		y = y_;
		z = z_;
	}

	//外積
	D3 Cross_product ( D3 partner )
	{
		D3 ret ( y*partner.z - z*partner.y , z*partner.x - x*partner.z , x*partner.y - y*partner.x );
		return ret;
	}

	//内積
	double Inner_product ( D3 partner )
	{
		return x*partner.x + y*partner.y + z*partner.z;
	}

	//二点からベクトルを作成
	D3 Make_vector ( D3 partner )
	{
		D3 ret ( partner.x - x , partner.y - y , partner.z - z );
		return ret;
	}

	//同一始点2ベクトルから面積を求める
	double S_vec ( D3 A , D3 B )
	{
		D3 G;
		G = A.Cross_product ( B );
		return sqrt ( G.Inner_product ( G ) ) / 2;
	}

	//三点から面積を求める
	double S_point ( D3 A , D3 B , D3 C )
	{
		return S_vec ( A.Make_vector ( B ) , A.Make_vector ( C ) );
	}

	//同一始点3ベクトルから体積を求める
	double V_vec ( D3 A , D3 B , D3 C )
	{
		D3 G;
		G = A.Cross_product ( B );
		return G.Inner_product ( C ) / 6;
	}

	//4点から体積を求める
	double V_point ( D3 A , D3 B , D3 C , D3 D )
	{
		return V_vec ( A.Make_vector ( B ) , A.Make_vector ( C ) , A.Make_vector ( D ) );
	}

};


int main ()
{
	D3 P;
	int N;
	cin >> N;
	cin >> P.x >> P.y >> P.z;
	vector<D3>Q ( N );
	for( size_t i = 0; i < N; i++ )
	{
		double x , y , z;
		cin >> x >> y >> z;
		Q[i] = D3 ( x , y , z );
	}
	double ans = 0.0;
	for( size_t i = 0; i < N; i++ )
	{
		for( size_t j = i + 1; j < N; j++ )
		{
			for( size_t k = j + 1; k < N; k++ )
			{
				D3 calc;
				double S = calc.S_point ( Q[i] , Q[j] , Q[k] );
				double V = calc.V_point ( Q[i] , Q[j] , Q[k] , P );

				ans += abs ( V *3.0 / S );
			}
		}
	}
	cout << fixed << setprecision ( 12 ) << ans << endl;
	return 0;
}
0