Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <algorithm>
- #include <iomanip>
- #include <queue>
- #include <stack>
- #include <climits>
- using namespace std;
- long n, m, a, b;
- vector <vector <double>> mas;
- struct ostrov {
- long x, y, r;
- };
- vector <ostrov> ostrov1;
- void dk() {
- vector <bool> used(n);
- vector <double> l(n, INT_MAX);
- l[a] = 0;
- for (long i = 0; i < n; i++)
- {
- long min = INT_MAX;
- long s = INT_MIN;
- for (long j = 0; j < n; j++)
- {
- if (!used[j] && l[j] < min) {
- min = l[j];
- s = j;
- }
- }
- if (s == INT_MIN) break;
- for (long j = 0; j < n; j++){
- if (!used[j] && mas[s][j] != -1) {
- if (l[s] + mas[s][j] < l[j]) {
- l[j] = l[s] + mas[s][j];
- }
- }
- }
- used[s] = true;
- }
- printf("%lf ", l[b]);
- }
- int main() {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- cin >> n;
- mas.resize(n); ostrov1.resize(n);
- for (long i = 0; i < n; i++){
- mas[i].resize(n);
- cin >> ostrov1[i].x >> ostrov1[i].y >> ostrov1[i].r;
- }
- for (long i = 0; i < n; i++) {
- for (long j = i + 1; j < n; j++){
- mas[i][j] = mas[j][i] =sqrt(abs(ostrov1[i].x - ostrov1[j].x) * abs(ostrov1[i].x - ostrov1[j].x)
- + abs(ostrov1[i].y - ostrov1[j].y) * abs(ostrov1[i].y - ostrov1[j].y))
- - ostrov1[i].r - ostrov1[j].r;
- }
- }
- cin >> m;
- for (long i = 0; i < m; i++){
- cin >> a >> b;
- a--; b--;
- dk();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement