結果

問題 No.622 点と三角柱の内外判定
ユーザー fura
提出日時 2020-06-01 04:36:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 971 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 194,056 KB
最終ジャッジ日時 2025-01-10 20:13:50
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         scanf("%lf%lf%lf",&a.x,&a.y,&a.z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%lf%lf%lf",&b.x,&b.y,&b.z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%lf%lf%lf",&c.x,&c.y,&c.z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf("%lf%lf%lf",&p.x,&p.y,&p.z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class point3{
public:
	double x,y,z;
	point3 operator-(const point3& p)const{ return {x-p.x,y-p.y,z-p.z}; }
};

point3 operator*(double c,const point3& p){ return {c*p.x,c*p.y,c*p.z}; }

double abs(const point3& p){ return sqrt(p.x*p.x+p.y*p.y+p.z*p.z); }

double dot(const point3& p,const point3& q){
	return p.x*q.x+p.y*q.y+p.z*q.z;
}

point3 cross(const point3& p,const point3& q){
	return {p.y*q.z-p.z*q.y,p.z*q.x-p.x*q.z,p.x*q.y-p.y*q.x};
}

int main(){
	point3 a,b,c,p;
	scanf("%lf%lf%lf",&a.x,&a.y,&a.z);
	scanf("%lf%lf%lf",&b.x,&b.y,&b.z);
	scanf("%lf%lf%lf",&c.x,&c.y,&c.z);
	scanf("%lf%lf%lf",&p.x,&p.y,&p.z);

	point3 n=cross(b-a,c-a);
	n=1/abs(n)*n;

	p=p-dot(p,n)*n;
	double s1=dot(cross(p-a,b-a),n);
	double s2=dot(cross(p-b,c-b),n);
	double s3=dot(cross(p-c,a-c),n);
	if((s1>0 && s2>0 && s3>0)
	|| (s1<0 && s2<0 && s3<0)) puts("YES");
	else puts("NO");

	return 0;
}
0