forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10075.cpp
113 lines (106 loc) · 1.98 KB
/
10075.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793
#define R 6378
#define MAX 110
#define INF 2147483647
int N, M, Q, index1, index2;
struct node
{
double lat, lon;
char name[100];
};
long long data[MAX][MAX];
node store[MAX];
double distance(double a_lat, double b_lat, double a_long, double b_long)
{
return R * acos(cos(a_lat) * cos(b_lat) * cos(a_long - b_long) + sin(a_lat) * sin(b_lat));
}
int index(char *name)
{
int i = 0;
for (; i < N; i++)
if (!strcmp(name, store[i].name))
{
return i;
}
return -1;
}
int main()
{
char temp[100], temp2[100];
bool next_line = false;
int times = 1;
while (scanf("%d %d %d", &N, &M, &Q))
{
if (N == 0 && M == 0 && Q == 0)
{
return 0;
}
if (next_line)
{
printf("\n");
}
next_line = true;
printf("Case #%d\n", times++);
//initial
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
data[i][j] = INF;
}
data[i][i] = 0;
}
//
for (int i = 0; i < N; i++)
{
scanf("%99s %lf %lf", store[i].name, &store[i].lat, &store[i].lon);
store[i].lat = store[i].lat * pi / 180.0;
store[i].lon = store[i].lon * pi / 180.0;
}
for (int k = 0; k < M; k++)
{
scanf("%99s %99s", temp, temp2);
index1 = index(temp);
index2 = index(temp2);
if (index1 == index2)
{
data[index1][index2] = 0;
}
else
{
data[index1][index2] = (long long)(distance(store[index1].lat, store[index2].lat, store[index1].lon, store[index2].lon) + 0.5);
}
}
//APSP
for (int k = 0; k < N; k++)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (data[i][k] + data[k][j] < data[i][j])
{
data[i][j] = data[i][k] + data[k][j];
}
}
}
}
for (int i = 0; i < Q; i++)
{
scanf("%99s %99s", temp, temp2);
index1 = index(temp);
index2 = index(temp2);
if (data[index1][index2] != INF)
{
printf("%lld km\n", data[index1][index2]);
}
else
{
printf("no route exists\n");
}
}
}
return 0;
}