fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <cmath>
  6. #include <set>
  7. #include <fstream>
  8. #include <cstring>
  9. #include <string>
  10. #include <algorithm>
  11. #include <map>
  12. #include <queue>
  13. #include <iterator>
  14. using namespace std;
  15.  
  16. #define sqr(x) ((x)*(x))
  17. #define cbr(x) ((x)*(x)*(x))
  18. #define max(a, b) (((a)<(b))? (b):(a))
  19. #define min(a, b) (((a)<(b))? (a):(b))
  20. #define all(a) a.begin(), a.end()
  21.  
  22. #define _sp system("pause");
  23. #define _ln cout << "------------------------------------------------\n";
  24. #define FI(a, n) for(int i=a;i<n;i++)
  25. #define FJ(a, n) for(int j=a;j<n;j++)
  26. #define REP(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
  27. #define rep(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
  28.  
  29. #define ll long long
  30. #define ull unsigned long long
  31. #define pii pair<int, int>
  32. #define mp(a, b) make_pair((a), (b))
  33. #define pb(a) push_back((a))
  34.  
  35. #define x1 sasimathx1
  36. #define y1 sasimathy1
  37.  
  38. void delbit(ll &a, ll k) { a &= (~(1 << k)); }
  39. bool getbit(ll a, ll k) { return 1 & (a >> k); }
  40. ll setbit(ll &a, ll k) { return a |= (1 << k); }
  41.  
  42. inline ll mulmod(ll x, ll n, ll _mod) { ll res = 0; while (n) { if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
  43. inline ll powmod(ll x, ll n, ll _mod) { ll res = 1; while (n) { if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
  44. inline ll gcd(ll a, ll b) { ll t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
  45. inline int gcd(int a, int b) { int t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
  46. inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
  47. inline ll gcd(ll a, ll b, ll c) { return gcd(gcd(a, b), c); }
  48. inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
  49. double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }
  50.  
  51. //constants
  52. #define PI 3.1415926535897932
  53. #define INF 2147483640
  54. #define LLINF 9223372036854775806
  55. #define eps 1e-14
  56. //-------------------------------------------------
  57. #define N 100010
  58.  
  59. pair<double, int> p[N];
  60. double da[N];
  61. int n;
  62.  
  63. double go(int j) {
  64. rep(0, n, i) {
  65. if (p[i].second != j)return p[i].first;
  66. }
  67. return LLINF;
  68. }
  69.  
  70. int main()
  71. {
  72. ios_base::sync_with_stdio(0);
  73. cin.tie(0);
  74.  
  75. double Ax, Bx, Tx, Ay, By, Ty, sum = 0;
  76. cin >> Ax >> Ay >> Bx >> By >> Tx >> Ty;
  77. cin >> n;
  78.  
  79. rep(0, n, i) {
  80. double x, y;
  81. cin >> x >> y;
  82. double add = dist(Tx, Ty, x, y);
  83. sum += add * 2;
  84. p[i].first = dist(Bx, By, x, y) - add;
  85. p[i].second = i;
  86. da[i] = dist(Ax, Ay, x, y) - add;
  87. }
  88.  
  89. sort(p, p + n);
  90.  
  91. double ans = LLINF;
  92. rep(0, n, i) {
  93. ans = min(ans, sum + da[i] + min(0, go(i)));
  94. }
  95. ans = min(ans, sum + go(-1));
  96.  
  97. printf("%.12lf\n", ans);
  98.  
  99. return 0;
  100. }
Success #stdin #stdout 0s 5412KB
stdin
Standard input is empty
stdout
9223372036854775808.000000000000