#include <bits/stdc++.h>using namespace Std;const int M = 1e5+10; Const double PI = ACOs ( -1.0); int n;d ouble sx, SY ;//source point double x[m], Y[m];d ouble minn = 1e18, MAXN = 1;d ouble dist (int id) {return sqrt ((X[ID]-SX) * (X[ID]-SX) + (y[id]- SY) * (Y[id]-sy));} Double segdist (int id1, int id2) {//source point to polygon two points Id1,id2 shortest distance double A = Y[id2]-Y[ID1]; Double b = x[id1]-X[ID2]; Double C = x[id2]*y[id1]-y[id2]*x[id1]; if ((X[id1]-x[id2]) * (Sx-x[id2]) + (Y[id1]-y[id2]) * (Sy-y[id2]) < 0) return 1e18;//If the perpendicular falls outside the line segment, return Infinity if ((X[ID2]-X[ID1]) * (Sx-x[id1]) + (Y[ID2]-Y[ID1]) * (SY-Y[ID1]) < 0) return 1e18;//take advantage of the dot product obtuse <0 return Fabs (c+sy*b+sx*a)/sqrt (a*a+b*b); Using cross product and area method}int main () {CIN >> n >> sx >> sy; for (int i = 0; i < n; i + +) {scanf ("%lf%lf", &x[i],&y[i]); } for (int i = 0; i < n; i + +) {MAXN = max (MAXN, Dist (i)); Minn = MIN (Minn, dist (i));//Perpendicular falls outside the segment, the shortest distance from the source to the segment Minn = MIN (Minn, segdiSt (I, (i+1)%n)); } cout.precision (12); cout << pi* (maxn*maxn-minn*minn) << Endl; return 0;}
The shortest distance from point to segment