結果
問題 | No.132 点と平面との距離 |
ユーザー | やまぞう |
提出日時 | 2015-04-19 23:15:20 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,079 bytes |
コンパイル時間 | 583 ms |
コンパイル使用メモリ | 68,276 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 18:10:40 |
合計ジャッジ時間 | 922 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
ソースコード
#include <iostream> #include <fstream> #include <vector> #include <cmath> using namespace std; template<typename T> class Point3 { public: T x, y, z; Point3() {} Point3(T x, T y, T z) : x(x), y(y), z(z) {} Point3(const Point3& src) : x(src.x), y(src.y), z(src.z) {} Point3 operator-() const { return Point3(-x, -y, -z); } Point3& operator=(const Point3& a) { if (&a != this) { x = a.x; y = a.y; z = a.z; } return *this; } Point3& operator+=(const Point3& a) { x += a.x; y += a.y; z += a.z; return *this; } Point3& operator-=(const Point3& a) { x -= a.x; y -= a.y; z -= a.z; return *this; } Point3 operator+(const Point3& a) const { Point3 r = *this; r += a; return r; } Point3 operator-(const Point3& a) const { Point3 r = *this; r -= a; return r; } }; typedef Point3<double> Point3d; istream& operator>>(istream& in, Point3d& p) { in >> p.x >> p.y >> p.z; return in; } template<typename T, size_t N> class Vec { public: T val[N]; T& operator[](size_t k) { return val[k]; } const T& operator[](size_t k) const { return val[k]; } Vec() {} Vec(T a1) { val[0] = a1; } Vec(T a1, T a2) { val[0] = a1; val[1] = a2; } Vec(T a1, T a2, T a3) { val[0] = a1; val[1] = a2; val[2] = a3; } Vec(T a1, T a2, T a3, T a4) { val[0] = a1; val[1] = a2; val[2] = a3; val[3] = a4; } Vec(const Vec& src) { for (size_t i = 0; i < N; i++) { val[i] = src.val[i]; } } Vec& operator=(const Vec& src) { if (&src != this) { for (size_t i = 0; i < N; i++) { val[i] = src.val[i]; } } } Vec& operator+=(const Vec& a) { for (size_t i = 0; i < N; i++) { val[i] += a.val[i]; } } Vec& operator-=(const Vec& a) { for (size_t i = 0; i < N; i++) { val[i] -= a.val[i]; } } }; template<typename T> class Vec3 : public Vec < T, 3 > { public: Vec3(const Point3<T>& src) : Vec<T,3>(src.x, src.y, src.z) {} }; typedef Vec3<double> Vec3d; template<typename T, size_t N> T dot(const Vec<T, N>& a, const Vec<T, N>& b) { T sum = 0; for (int i = 0; i < N; i++) { sum += a[i] * b[i]; } return sum; } class Plane { public: double a, b, c, d; Plane() {} Plane(double a, double b, double c, double d) : a(a), b(b), c(c), d(d) {} Plane(const Point3d& p1, const Point3d& p2, const Point3d& p3) { Vec3d ab = p2 - p1; Vec3d ac = p3 - p1; a = ab[1] * ac[2] - ab[2] * ac[1]; b = ab[2] * ac[0] - ab[0] * ac[2]; c = ab[0] * ac[1] - ab[1] * ac[0]; d = -(a * p1.x + b * p1.y + c * p1.z); double n = sqrt(a * a + b * b + c * c); a /= n; b /= n; c /= n; d /= n; } }; int main() { #if 0 ifstream in("len003.txt"); #define out cout #else #define in cin #define out cout #endif int n; in >> n; Point3d P; in >> P; vector<Point3d> Q(n); for (int i = 0; i < n; i++) { in >> Q[i]; Q[i] -= P; } double sum = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { Plane plane(Q[i], Q[j], Q[k]); double distance = fabs(plane.d); sum += distance; } } } out << sum << endl; }