結果

問題 No.132 点と平面との距離
ユーザー bal4ubal4u
提出日時 2019-08-02 20:29:13
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,680 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 31,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 18:27:13
合計ジャッジ時間 1,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 10 ms
4,384 KB
testcase_02 AC 32 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: 備考: in expansion of macro ‘gc’
   16 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// 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