-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2099.cpp
More file actions
42 lines (38 loc) · 1.17 KB
/
2099.cpp
File metadata and controls
42 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
bool cmp (long long a, long long b){
if (b > 0)
return a >= b;
else
return a <= b;
}
bool run()
{
long long Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Dx, Dy, Dz;
cin >> Ax >> Ay >> Az >> Bx >> By >> Bz >> Cx >> Cy >> Cz >> Dx >> Dy >> Dz;
long long u = Dx - Ax, v = Dy - Ay, w = Dz - Az;
long long a = Bx - Ax, b = Dx - Cx, c = By - Ay, d = Dy - Cy, e = Bz - Az, f = Dz - Cz;
if ((Bx - Ax) * (Cx - Dx) + (By - Ay) * (Cy - Dy) + (Bz - Az) * (Cz - Dz) != 0)
return false;
long long t, s, det;
if (a * d != b * c)
t = u * d - b * v, s = v * a - u * c, det = a * d - b * c;
else if (c * f != d * e)
t = f * v - d * w, s = c * w - e * v, det = c * f - d * e;
else if (a * f != b * e)
t = u * f - b * w, s = a * w - e * u, det = a * f - b * e;
else
return false;
if (!cmp(t, det) || !cmp(s, det))
return false;
if (t * a + b * s != det * u || t * c + s * d != det * v || t * e + s * f != det * w)
return false;
return true;
}
int main()
{
if (run())
cout << "Valid";
else
cout << "Invalid";
}