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
101 lines (84 loc) · 2.98 KB
/
A.cpp
File metadata and controls
101 lines (84 loc) · 2.98 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
#include <bits/stdc++.h>
#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 SZ(x) ((int) (x).size())
#define D double
using namespace std;
#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;
Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
Point operator + (Point a) { return Point(x+a.x, y+a.y); }
Point operator - (Point a) { return Point(x-a.x, y-a.y); }
Point operator * (double k) { return Point(x*k, y*k); }
Point operator / (double k) { return Point(x/k, y/k); }
double operator * (Point a) { return x*a.x + y*a.y; } // dot product
double operator % (Point a) { 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; }
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;
scanf("%d", &t); x = t;
scanf("%d", &t); y = t;
}
} a[100111];
double distToLine(Point p, Point a, Point b, Point &c) {
Point ap = p - a, ab = b - a;
double u = (ap * ab) / ab.norm();
c = a + (ab * u);
return (p-c).len();
}
double distToLineSegment(Point p, Point a, Point b, Point &c) {
Point ap = p - a, ab = b - a;
double u = (ap * ab) / ab.norm();
if (u < 0.0) {
c = Point(a.x, a.y);
return (p - a).len();
}
if (u > 1.0) {
c = Point(b.x, b.y);
return (p - b).len();
}
return distToLine(p, a, b, c);
}
int main() {
int n;
while (scanf("%d", &n) == 1) {
Point P;
P.read();
FOR(i,1,n) {
a[i].read();
a[i] = a[i] - P;
}
a[0] = a[n];
a[n+1] = a[1];
D min_dist = 1e20, max_dist = -1;
if (min_dist < 0) min_dist = 0;
Point O(0, 0);
Point t;
FOR(i,1,n) {
min_dist = min(min_dist, a[i].len());
max_dist = max(max_dist, a[i].len());
min_dist = min(min_dist, distToLineSegment(O, a[i], a[i+1], t));
}
cout << (fixed) << setprecision(12) << acos(-1.0) * (sqr(max_dist) - sqr(min_dist)) << endl;
}
}