結果

問題 No.132 点と平面との距離
コンテスト
ユーザー bal4u
提出日時 2019-08-02 20:29:13
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,680 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 485 ms
コンパイル使用メモリ 44,648 KB
最終ジャッジ日時 2026-02-22 04:04:36
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.132 点と平面との距離
// 2019.8.2 bal4u

#include <stdio.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

double getdbl() {   // 実数の入力
	int minus = 0;
	double x, y;
	int n = 0, c = gc();
	if (c == '-') minus = 1, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = gc();
		do y *= 0.1, x += y * (c & 0xf), c = gc(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

typedef struct { double x, y, z; } PP;      // Point
typedef struct { double a, b, c, d; } PL;   // Plane

double distPlP(PL *pl, PP *p) {
	double t = fabs(pl->a * p->x + pl->b * p->y + pl->c * p->z + pl->d);
	return t/sqrt(p->x * p->x + p->y * p->y + p->z * p->z);
}

PP p, q[305];
int N;

int main()
{
	int i, j, k;
	PP t; PL pl;
	double ans;
	
	N = in();
	p.x = getdbl(), p.y = getdbl(), p.z = getdbl();
	for (i = 0; i < N; i++) {
		q[i].x = getdbl(), q[i].y = getdbl(), q[i].z = getdbl();
	}
	ans = 0, pl.d = 0;
	for (i = 0; i < N; i++) for (j = i+1; j < N; j++) for (k = j+1; k < N; k++) {
		t.x = (q[j].y-q[i].y) * (q[k].z-q[i].z) - (q[j].z-q[i].z) * (q[k].y-q[i].y);
		t.y = (q[j].z-q[i].z) * (q[k].x-q[i].x) - (q[j].x-q[i].x) * (q[k].z-q[i].z);
		t.z = (q[j].x-q[i].x) * (q[k].y-q[i].y) - (q[j].y-q[i].y) * (q[k].x-q[i].x);
		pl.a = p.x - q[i].x, pl.b = p.y - q[i].y, pl.c = p.z - q[i].z;
		ans += distPlP(&pl, &t);
	}
	printf("%.12lf\n", ans);
	return 0;
}
0