結果
問題 | No.622 点と三角柱の内外判定 |
ユーザー |
![]() |
提出日時 | 2017-12-24 12:04:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 2,389 bytes |
コンパイル時間 | 1,691 ms |
コンパイル使用メモリ | 170,172 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 18:26:59 |
合計ジャッジ時間 | 2,523 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include "bits/stdc++.h"using namespace std;#define DEBUG(x) cout<<#x<<": "<<x<<endl;#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endltypedef long long ll;#define vi vector<int>#define vl vector<ll>#define vii vector< vector<int> >#define vll vector< vector<ll> >#define vs vector<string>#define pii pair<int,int>#define pis pair<int,string>#define psi pair<string,int>#define pll pair<ll,ll>const int inf = 1000000001;const ll INF = 2e18 * 2;#define MOD 1000000007#define mod 1000000009#define pi 3.14159265358979323846#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };#define P complex<double>// 外積 (cross product) : a×b = |a||b|sinΘdouble cross(P a, P b) {return (a.real() * b.imag() - a.imag() * b.real());}int main() {int i, j;vector<double> x(4), y(4), z(4);for (i = 0; i < 4; i++) {cin >> x[i] >> y[i] >> z[i];}for (i = 3; i >= 0; i--) {x[i] -= x[0];y[i] -= y[0];z[i] -= z[0];}/*for (i = 0; i < 4; i++) {printf("(%lf, %lf, %lf)\n", x[i], y[i], z[i]);}cout << endl;//*/double theta = atan2(y[1], x[1]);for (i = 3; i >= 1; i--) {double xt = x[i], yt = y[i];x[i] = xt*cos(theta) + yt*sin(theta);y[i] = yt*cos(theta) - xt*sin(theta);}/*for (i = 0; i < 4; i++) {printf("(%lf, %lf, %lf)\n", x[i], y[i], z[i]);}cout << endl;//*/theta = atan2(z[1], x[1]);for (i = 3; i >= 1; i--) {double xt = x[i], zt = z[i];x[i] = xt * cos(theta) + zt * sin(theta);z[i] = zt * cos(theta) - xt * sin(theta);}/*for (i = 0; i < 4; i++) {printf("(%lf, %lf, %lf)\n", x[i], y[i], z[i]);}cout << endl;//*/theta = atan2(z[2], y[2]);for (i = 3; i >= 2; i--) {double yt = y[i], zt = z[i];y[i] = yt * cos(theta) + zt * sin(theta);z[i] = zt * cos(theta) - yt * sin(theta);}/*for (i = 0; i < 4; i++) {printf("(%lf, %lf, %lf)\n", x[i], y[i], z[i]);}cout << endl;//*/P p[4];for (i = 0; i < 4; i++) {p[i].real(x[i]);p[i].imag(y[i]);}vector<double> c(3);for (i = 0; i < 3; i++) {c[i] = cross(p[(i + 1) % 3] - p[i], p[3] - p[(i + 1) % 3]);}if ((c[0] > 0 && c[1] > 0 && c[2] > 0) || (c[0] < 0 && c[1] < 0 && c[2] < 0)) {cout << "YES" << endl;}else {cout << "NO" << endl;}}