fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define f first
  6. #define s second
  7.  
  8. double dist(int x1, int y1, int x2, int y2) {
  9. int a = x1 - x2, b = y1 - y2;
  10. return sqrt( (x1-x2)*(x1-x2) + (y1-y2) * (y1-y2));
  11. }
  12.  
  13. int main() {
  14. pair<int,int> adil, ber, bin;
  15. double total = 0;
  16.  
  17. cin >> adil.f >> adil.s;
  18. cin >> ber.f >> ber.s;
  19. cin >> bin.f >> bin.s;
  20.  
  21. int n;
  22.  
  23. cin >> n;
  24.  
  25. vector<pair<int,int> > rub(n);
  26.  
  27. for (int i = 0; i < n; i++) {
  28. cin >> rub[i].f >> rub[i].s;
  29. total += 2 * dist(rub[i].f, rub[i].s,bin.f, bin.s);
  30.  
  31. }
  32.  
  33. vector<double> a(n), b(n);
  34.  
  35. double ans = 1e15, p1 = 1e15, p2 = 1e15;
  36.  
  37. for (int i = 0; i < n; i++) {
  38. a[i] = dist(adil.f, adil.s, rub[i].f, rub[i].s) - dist(rub[i].f, rub[i].s, bin.f, bin.s);
  39. b[i] = dist(ber.f, ber.s, rub[i].f, rub[i].s) - dist(rub[i].f, rub[i].s, bin.f, bin.s);
  40.  
  41. ans = min(ans, a[i]);
  42. ans = min(ans, b[i]);
  43.  
  44. ans = min(ans, a[i] + p2);
  45. ans = min(ans, b[i] + p1);
  46.  
  47. p1 = min(p1, a[i]);
  48. p2 = min(p2, b[i]);
  49.  
  50. }
  51.  
  52. ans += total;
  53.  
  54. cout << fixed << double(ans);
  55.  
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
0.000000