結果

問題 No.132 点と平面との距離
ユーザー Ysmr_RyYsmr_Ry
提出日時 2015-01-24 01:03:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 34,828 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 04:20:31
合計ジャッジ時間 951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder 132 (http://yukicoder.me/problems/147)
#include<cstdio>
#include<cmath>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_N = 300;

struct Pt
{
	double x, y, z;

	Pt( double x = 0, double y = 0, double z = 0 )
	:	x(x), y(y), z(z)
	{}

	Pt operator- ( const Pt &p ) const
	{ return Pt( x-p.x, y-p.y, z-p.z ); }

	double norm() const
	{ return sqrt(x*x+y*y+z*z); }

	double dot( const Pt &p ) const
	{ return x*p.x+y*p.y+z*p.z; }

	Pt cross( const Pt &p ) const
	{ return Pt( y*p.z-z*p.y, z*p.x-x*p.z, x*p.y-y*p.x ); }
};

int N;
Pt P, pts[MAX_N];

double dist( int i, int j, int k )
{
	Pt n = (pts[j]-pts[i]).cross( pts[k]-pts[i] );
	
	return fabs(n.dot(P)-pts[i].dot(n))/n.norm();
}

int main()
{
	scanf( "%d%lf%lf%lf", &N, &P.x, &P.y, &P.z );
	rep( i, N )
		scanf( "%lf%lf%lf", &pts[i].x, &pts[i].y, &pts[i].z );

	double ans = 0;
	rep( i, N ) rep( j, i ) rep( k, j )
		ans += dist(i,j,k);

	printf( "%.12f\n", ans );

	return 0;
}
0