-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatapultas.cpp
68 lines (57 loc) · 1.45 KB
/
catapultas.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
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define x first
#define y second
using namespace std;
int main(){
long n, px, py, lx, ly;
while(cin >> n >> px >> py >> lx >> ly){
vector<pair<int, int> > cat;
vector<int> fs;
vector<double> dist;
vector<bool> visitado;
if(n == -1) return 0;
cat.push_back(make_pair(px, py));
fs.push_back(0);
dist.push_back(0);
visitado.push_back(true);
int cx, cy, f;
for(int i = 0; i < n; i++){
cin >> cx >> cy >> f;
cat.push_back(make_pair(cx, cy));
fs.push_back(f);
dist.push_back(9999999999);
visitado.push_back(false);
}
cat.push_back(make_pair(lx, ly));
fs.push_back(0);
dist.push_back(9999999999);
visitado.push_back(false);
for(int i = 0; i < n+2; i++){
int curr = i;
visitado[i] = true;
for(int j = 0; j < n+2; j++){
if(!visitado[j]){
double d = abs( pow (pow(cat[curr].x - cat[j].x,2) + pow(cat[curr].y - cat[j].y, 2), 0.5) - fs[curr]);
if (dist[j] > dist[curr] + d){
dist[j] = dist[curr] + d;
}
}
}
for(int j = 0; j < n; j++){
double minCurr = 9999999999;
if(!visitado[j] && dist[j] < minCurr){
curr = j;
}
}
if(curr == n+2){
double d = ((double)floor(dist[curr] * 100 + 0.5)) / 100.0;
printf("%.2f", d);
break;
}
}
}
return 0;
}