-
Notifications
You must be signed in to change notification settings - Fork 166
/
spheres.cpp
62 lines (60 loc) · 1.17 KB
/
spheres.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//spheres.cpp
//Spheres
//Ad Infinitum - Math Programming Contest June'14
//Author: derekhh
#include<iostream>
#include<string>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int r1, r2;
cin >> r1 >> r2;
int x1, y1, z1, x2, y2, z2;
int a1x, a1y, a1z, a2x, a2y, a2z;
cin >> x1 >> y1 >> z1 >> a1x >> a1y >> a1z;
cin >> x2 >> y2 >> z2 >> a2x >> a2y >> a2z;
double a = ((a1x - a2x) * (a1x - a2x) + (a1y - a2y) * (a1y - a2y) + (a1z - a2z)*(a1z - a2z)) * 0.25;
double b = (x1 - x2) * (a1x - a2x) + (y1 - y2) * (a1y - a2y) + (z1 - z2) * (a1z - a2z);
double c = (x1 - x2)*(x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2) - (r1 + r2) * (r1 + r2);
//cout << a << " " << b << " " << c << endl;
string res;
if (a == 0)
{
if (b == 0)
{
res = (c >= 0)? "NO" : "YES";
}
else
{
res = (b > 0 && c >= 0) ? "NO" : "YES";
}
}
else
{
if (a < 0) res = "YES";
else
{
if (b <= 0)
{
if (((4 * a * c - b * b) / (4 * a)) >= 0)
res = "NO";
else
res = "YES";
}
else
{
if (c >= 0)
res = "NO";
else
res = "YES";
}
}
}
cout << res << endl;
}
return 0;
}