forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAircraft.cpp
36 lines (31 loc) · 1.03 KB
/
Aircraft.cpp
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
#line 115 "Aircraft.cpp"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Aircraft
{
public:
string nearMiss(vector <int> p1, vector <int> v1, vector <int> p2, vector <int> v2, int R)
{
int r[3], v[3];
for(int i = 0; i < 3; i++){
r[i] = p1[i]-p2[i];
v[i] = v1[i]-v2[i];
}
int num = -(r[0]*v[0]+r[1]*v[1]+r[2]*v[2]);
int dnum = (v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
if((r[0]*r[0]+r[1]*r[1]+r[2]*r[2]) < R*R)
return "YES";
if(dnum == 0 || num < 0) return "NO";
double t = num/dnum;
double rx = 0.0;
for(int i = 0; i < 3; i++)
rx += (p1[i]+v1[i]*t-p2[i]-v2[i]*t)*(p1[i]+v1[i]*t-p2[i]-v2[i]*t);
if(rx <= R*R) return "YES";
else return "NO";
}
};
int main(){}
// Powered by FileEdit
// Powered by FileEdit