forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
1001.cpp
87 lines (83 loc) · 1.4 KB
/
1001.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
const int INF = 0x7fffffff;
struct node
{
int x;
int y;
int z;
int r;
} a[110];
double dis(int i, int j)
{
if (i == j)
{
return 0.0;
}
else
{
return sqrt(1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x) + (a[i].y - a[j].y) * (a[i].y - a[j].y) + (a[i].z - a[j].z) * (a[i].z - a[j].z));
}
}
int main()
{
int n, kase = 1;
double road[110][110];
double d[110][110];
while (cin >> n)
{
for (int i = 0; i <= n + 1; i++)
{
for (int j = 0; j <= n + 1; j++)
{
if (i == j)
{
d[i][j] = 0;
}
else
{
d[i][j] = INF;
}
}
}
if (n < 0)
{
return 0;
}
for (int i = 1; i <= n; i++)
{
cin >> a[i].x >> a[i].y >> a[i].z >> a[i].r;
}
cin >> a[0].x >> a[0].y >> a[0].z;
a[0].r = a[n + 1].r = 0;
cin >> a[n + 1].x >> a[n + 1].y >> a[n + 1].z;
for (int i = 0; i <= n + 1; i++)
{
for (int j = 0; j <= n + 1; j++)
{
if (dis(i, j) - a[i].r - a[j].r > 0.0)
{
d[i][j] = dis(i, j) - a[i].r - a[j].r;
}
else
{
d[i][j] = 0.0;
}
}
}
for (int k = 0; k <= n + 1; k++)
{
for (int i = 0; i <= n + 1; i++)
{
for (int j = 0; j <= n + 1; j++)
{
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
int kk = int(d[0][n + 1] * 10 + 0.5 + 1e-7);
cout << "Cheese " << kase++ << ": Travel time = " << kk << " sec" << endl;
}
return 0;
}