fork(11) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define pb push_back
  6. #define orta (bas + son >> 1)
  7. #define sag (k + k + 1)
  8. #define sol (k + k)
  9. #define endl '\n'
  10. #define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
  11. #define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
  12. #define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
  13. #define mp make_pair
  14. #define nd second
  15. #define st first
  16. #define type(x) __typeof(x.begin())
  17.  
  18. typedef pair < int ,int > pii;
  19.  
  20. typedef long long ll;
  21.  
  22. const long long linf = 1e18+5;
  23. const int mod = (int) 1e9 + 7;
  24. const int logN = 17;
  25. const int inf = 1e9;
  26. const int N = 1e6 + 5;
  27.  
  28. int Kx, Ky, Cx, Cy, Tx, Ty, n, x, y;
  29.  
  30. double pre[N], suff[N], add[N], all;
  31.  
  32. double dist(int x, int y, int a, int b) { return sqrt((ll) (x - a) * (x - a) + (ll) (y - b) * (y - b)); }
  33.  
  34. int main() {
  35.  
  36. scanf("%d %d %d %d %d %d", &Kx, &Ky, &Cx, &Cy, &Tx, &Ty);
  37.  
  38. scanf("%d", &n);
  39.  
  40. FOR(i, 1, n) {
  41. scanf("%d %d", &x, &y);
  42. double add = dist(Tx, Ty, x, y);
  43. all += add * 2;
  44. suff[i] = pre[i] = dist(Cx, Cy, x, y) - add;
  45. ::add[i] = dist(Kx, Ky, x, y) - add;
  46. }
  47.  
  48. pre[0] = suff[n+1] = linf;
  49. FOR(i, 1, n) { pre[i] = min(pre[i-1], pre[i]); }
  50. ROF(i, n, 1) { suff[i] = min(suff[i+1], suff[i]); }
  51.  
  52. double ans = suff[1] + all;
  53.  
  54. FOR(i, 1, n)
  55. ans = min(ans, all + min(0.0, min(pre[i-1], suff[i+1])) + add[i]);
  56.  
  57. printf("%.12lf\n", ans);
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 26856KB
stdin
Standard input is empty
stdout
1000000000000000000.000000000000