結果
| 問題 | No.132 点と平面との距離 |
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2015-01-24 01:03:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 5,000 ms |
| コード長 | 950 bytes |
| 記録 | |
| コンパイル時間 | 342 ms |
| コンパイル使用メモリ | 32,640 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 00:58:42 |
| 合計ジャッジ時間 | 752 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf( "%d%lf%lf%lf", &N, &P.x, &P.y, &P.z );
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf( "%lf%lf%lf", &pts[i].x, &pts[i].y, &pts[i].z );
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
// 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;
}
Ysmr_Ry