結果

問題 No.622 点と三角柱の内外判定
ユーザー merom686merom686
提出日時 2017-12-22 17:26:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,434 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 21:19:38
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct V {
    static constexpr int N = 3;
    double inner(const V& v) const {
        double t = 0;
        for (int i = 0; i < N; i++) {
            t += x[i] * v.x[i];
        }
        return t;
    }
    V cross(const V& v) const {
        return V{
            x[1] * v.x[2] - x[2] * v.x[1],
            x[2] * v.x[0] - x[0] * v.x[2],
            x[0] * v.x[1] - x[1] * v.x[0],
        };
    }
    V& operator-=(const V& v) {
        for (int i = 0; i < N; i++) {
            x[i] -= v.x[i];
        }
        return *this;
    }
    V& operator*=(double t) {
        for (int i = 0; i < N; i++) {
            x[i] *= t;
        }
        return *this;
    }
    double& operator[](int i) {
        return x[i];
    }
    double x[N];
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    V v[4];
    for (int i = 0; i < 4; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    for (int i = 0; i < 4; i++) {
        if (i != 2) v[i] -= v[2];
    }

    V v2 = v[0].cross(v[1]);
    V v0 = v2.cross(v[1]);
    V v1 = v2.cross(v[0]);
    v0 *= 1 / v[0].inner(v0);
    v1 *= 1 / v[1].inner(v1);

    double s0 = v[3].inner(v0);
    double s1 = v[3].inner(v1);

    cout << ((s0 + s1 < 1 && s0 > 0 && s1 > 0) ? "YES" : "NO") << endl;

    return 0;
}
0