forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
104 lines (85 loc) · 3.08 KB
/
A.cpp
File metadata and controls
104 lines (85 loc) · 3.08 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int) (x).size())
using namespace std;
double safe_sqrt(double x) {
return sqrt(max((double)0.0,x));
}
int GI(ll& x) {
return scanf("%lld", &x);
}
const int MN = 100111;
#define EPS 1e-6
inline int cmp(double a, double b) {
return (a < b - EPS) ? -1 : ((a > b + EPS) ? 1 : 0);
}
struct Point {
double x, y;
int id;
Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
Point operator + (const Point& a) const { return Point(x+a.x, y+a.y); }
Point operator - (const Point& a) const { return Point(x-a.x, y-a.y); }
Point operator * (double k) const { return Point(x*k, y*k); }
Point operator / (double k) const { return Point(x/k, y/k); }
double operator * (const Point& a) const { return x*a.x + y*a.y; } // dot product
double operator % (const Point& a) const { return x*a.y - y*a.x; } // cross product
int cmp(Point q) const { if (int t = ::cmp(x,q.x)) return t; return ::cmp(y,q.y); }
#define Comp(x) bool operator x (Point q) const { return cmp(q) x 0; }
Comp(>) Comp(<) Comp(==) Comp(>=) Comp(<=) Comp(!=)
#undef Comp
Point conj() { return Point(x, -y); }
double norm() { return x*x + y*y; }
// Note: There are 2 ways for implementing len():
// 1. sqrt(norm()) --> fast, but inaccurate (produce some values that are of order X^2)
// 2. hypot(x, y) --> slow, but much more accurate
double len() { return sqrt(norm()); }
Point rotate(double alpha) {
double cosa = cos(alpha), sina = sin(alpha);
return Point(x * cosa - y * sina, x * sina + y * cosa);
}
void read() {
int t;
GI(t); x = t;
GI(t); y = t;
}
};
Point A, B, R;
Point P[MN];
int n;
pair<double,int> fa[MN], fb[MN];
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
cout << (fixed) << setprecision(15);
A.read(); B.read(); R.read();
GI(n);
double sum = 0;
FOR(i,1,n) {
P[i].read();
fa[i] = make_pair( (P[i] - R).len() - (P[i] - A).len(), i );
fb[i] = make_pair( (P[i] - R).len() - (P[i] - B).len(), i );
sum += (P[i] - R).len();
}
sum *= 2.0;
sort(fa+1, fa+n+1);
sort(fb+1, fb+n+1);
double res = 1e100;
res = min(res, sum - fa[n].first);
res = min(res, sum - fb[n].first);
if (n >= 2) {
FOR(i,n-1,n) FOR(j,n-1,n) if (fa[i].second != fb[j].second) {
res = min(res, sum - fa[i].first - fb[j].first);
}
}
cout << res << endl;
}