結果

問題 No.622 点と三角柱の内外判定
ユーザー ふっぴーふっぴー
提出日時 2017-12-22 00:35:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,336 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 168,280 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-22 21:12:40
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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<<endl

typedef 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>
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

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];
		x[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] = dot(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;
	}
}
0