結果
| 問題 | No.622 点と三角柱の内外判定 | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2017-12-22 17:26:51 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 1,500 ms | 
| コード長 | 1,434 bytes | 
| コンパイル時間 | 631 ms | 
| コンパイル使用メモリ | 75,028 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-12-17 23:13:27 | 
| 合計ジャッジ時間 | 1,621 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
#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;
}
            
            
            
        