結果

問題 No.622 点と三角柱の内外判定
ユーザー peroon
提出日時 2019-05-03 17:05:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 2,878 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 169,920 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 15:43:54
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template < typename T >
void vprint(T &V){
for(auto v : V){
cout << v << " ";
}
cout << endl;
}
// 3
struct V3{
double x, y, z;
V3(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}
};
V3 operator+(V3 a, V3 b) {
return V3(a.x + b.x, a.y + b.y, a.z + b.z);
}
V3 operator-(V3 a, V3 b) {
return V3(a.x - b.x, a.y - b.y, a.z - b.z);
}
V3 operator*(V3 a, double b) {
return V3(a.x * b, a.y * b, a.z * b);
}
V3 operator*(double b, V3 a) {
return V3(a.x * b, a.y * b, a.z * b);
}
V3 operator/(V3 a, double b) {
return V3(a.x / b, a.y / b, a.z / b);
}
//
double dot(V3 a, V3 b) {
return a.x*b.x + a.y*b.y + a.z*b.z;
}
//
V3 cross(V3 u, V3 v) {
return V3((u.y * v.z - u.z * v.y),
(u.z * v.x - u.x * v.z),
(u.x * v.y - u.y * v.x));
}
double abs(V3 a) {
double len = sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
if(len==0){
cout << "warning";
}
return sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
}
V3 normalize(V3 a) {
if(a.x==0 && a.y==0 && a.z==0){
return a;
}
return a / abs(a);
}
V3 proj(V3 a, V3 b) {
a = normalize(a);
return a * dot(a, b);
}
void printV3(V3 a){
cout << a.x << ' ' << a.y << ' ' << a.z << endl;
}
ll sign(double a){
if(a>=0){
return 1;
}else{
return -1;
}
}
// d
bool in_triangle(V3 a, V3 b, V3 c, V3 d){
auto AB = b-a;
auto BC = c-b;
auto CA = a-c;
auto AD = d-a;
auto BD = d-b;
auto CD = d-c;
auto c0 = cross(AB, AD);
auto c1 = cross(BC, BD);
auto c2 = cross(CA, CD);
auto dot0 = dot(c0, c1);
auto dot1 = dot(c1, c2);
auto dot2 = dot(c2, c0);
if(sign(dot0)==sign(dot1) && sign(dot1)==sign(dot2)){
return true;
}else{
return false;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
V3 V[4];
FOR(i, 0, 4){
cin >> V[i].x >> V[i].y >> V[i].z;
}
auto AA = V[0] - V[0];
auto AB = V[1] - V[0];
auto AC = V[2] - V[0];
auto n = cross(AB, AC);
n = normalize(n);
auto AD = V[3] - V[0];
auto a = AD;
auto AE = a - dot(a, n) * n;
bool f = in_triangle(AA, AB, AC, AE);
if(f){
p_yes();
}else{
p_no();
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0