# CFR 613 A. Peter and Snow Blower ( Geometry )

Problem - A - Codeforces

N ≤ 1e5

1. 最近點在線段端點
2. 最近點在該點在線段的投射處

( A.x + ( A->B ).x * len / | A->B |, A.y + ( A->B ).y * len / | A->B | )

O( N )

```#include <bits/stdc++.h>
using namespace std;

const int MAXN = ( int ) 1e5;

int N, sx, sy;
int X[ MAXN ], Y[ MAXN ];

double sqr( double x ){
return x * x;
}

double dis( double x1, double y1, double x2, double y2 ){
return sqrt( sqr( x1 - x2 ) + sqr( y1 - y2 ) );
}

double length( pair< double, double > p ){
return sqrt( sqr( p.first ) + sqr( p.second ) );
}

signed main(){
ios::sync_with_stdio( 0 );
{
cin >> N >> sx >> sy;
for( int i = 0; i < N; ++i ){
cin >> X[ i ] >> Y[ i ];
}
}
{
double maxr = 0.0, minr = 1e9;
for( int i = 0; i < N; ++i ){
maxr = max( maxr, dis( sx, sy, X[ i ], Y[ i ] ) );
int j = ( i + 1 ) % N;
minr = min( minr, dis( sx, sy, X[ i ], Y[ i ] ) );
pair< double, double > zs = make_pair( sx - X[ i ], sy - Y[ i ] );
pair< double, double > zp = make_pair( X[ j ] - X[ i ], Y[ j ] - Y[ i ] );
double xaji = zs.first * zp.first + zs.second * zp.second;
double len = fabs( xaji / length( zp ) );
if( len >= length( zp ) ) continue;
pair< double, double > m = make_pair( zp.first * len / length( zp ),
zp.second * len / length( zp ) );
minr = min( minr, dis( sx, sy, X[ i ] + m.first, Y[ i ] + m.second ) );
}
double ans = ( sqr( maxr ) - sqr( minr ) ) * acos( -1.0 );
cout << fixed << setprecision( 9 ) << ans << endl;
}
return 0;
}
```