結果
| 問題 | No.132 点と平面との距離 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-02 20:29:13 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 5,000 ms |
| コード長 | 1,680 bytes |
| 記録 | |
| コンパイル時間 | 1,302 ms |
| コンパイル使用メモリ | 32,640 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 08:16:50 |
| 合計ジャッジ時間 | 825 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:16:24: note: in expansion of macro 'gc'
16 | int n = 0, c = gc();
| ^~
ソースコード
// 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;
}
bal4u