fork download
  1. #define _USE_MATH_DEFINES
  2. #include<iostream>
  3. #include<complex>
  4. #include<cmath>
  5. #include<climits>
  6. #include<iomanip>
  7. using namespace std ;
  8. typedef long double T ;
  9. typedef complex<T> pt;
  10. #define f(i,s,n) for(int i=s;i<n;i++)
  11. // typedef long double T ;
  12. #define x real()
  13. #define y imag()
  14. T dot(pt v,pt w) {return v.x*w.x + v.y*w.y;}
  15. T cross(pt v,pt w) {return v.x*w.y - v.y*w.x;}
  16. struct line
  17. {
  18. pt v;
  19. T c ;
  20. };
  21. // T dot(pt v,pt w){return (conj(v)*w).x;}
  22. // T cross(pt v,pt w){return (conj(v)*w).y;}
  23. pt perp(pt p) {return {-p.y, p.x};}
  24. line perp_line(line l,pt P)
  25. {
  26. line l2 ;
  27. l2.v = perp(l.v) ;
  28. l2.c = cross(l2.v,P) ;
  29. return l2 ;
  30. }
  31. pt getv(pt a,pt b)
  32. {
  33. return {b.x-a.x,b.y-a.y} ;
  34. }
  35. bool intersect(line l1,line l2,pt& out)
  36. {
  37. T d = cross(l1.v, l2.v);
  38. if (d == 0) return false;
  39. out = (l2.v*l1.c - l1.v*l2.c) / d; // requires floating-point coordinates
  40. // T xx = (l2.v.x*l1.c-l1.v.x*l2.c)/d ;
  41. // T yy = (l2.v.y*l1.c-l1.v.y*l2.c)/d ;
  42. // out = {xx,yy} ;
  43. return true;
  44. }
  45. pt poi(line l1,pt P)
  46. {
  47. line l2 = perp_line(l1,P) ;
  48. pt out ;
  49. intersect(l1,l2,out) ;
  50. return out ;
  51. }
  52. T dist(pt A,pt B)
  53. {
  54. return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) ;
  55. }
  56. bool inseg(pt a,pt b,pt p)
  57. {
  58. return p.x<=max(a.x,b.x) && p.x>=min(a.x,b.x) && p.y<=max(a.y,b.y) && p.y>=min(a.y,b.y);
  59. }
  60. const int MAXN = 1e5+5 ;
  61. pt pts[MAXN] ;
  62. int main()
  63. {
  64. ios::sync_with_stdio(0) ;
  65. cin.tie(0);cout.tie(0) ;
  66. int n;T px,py;
  67. pt P ;cin>>n>>px>>py ;
  68. P = {px,py} ;
  69. T maxd = 0,mind = LONG_MAX ;
  70. f(i,0,n)
  71. {
  72. T a,b ;
  73. cin>>a>>b ;
  74. pts[i] = {a,b} ;
  75. maxd = max(maxd,dist(P,pts[i])) ;
  76. mind = min(mind,dist(P,pts[i])) ;
  77. }
  78. f(i,0,n)
  79. {
  80. int j = (i+1)%n ;
  81. line l ;
  82. l.v = getv(pts[i],pts[j]) ;
  83. l.c = cross(l.v,pts[i]) ;
  84. pt poii = poi(l,P) ;
  85. if(inseg(pts[i],pts[j],poii))
  86. {
  87. mind = min(mind,dist(poii,P)) ;
  88. }
  89. }
  90. cout<<setprecision(50)<<M_PI*(maxd-mind)<<"\n" ;
  91.  
  92. }
Success #stdin #stdout 0s 4404KB
stdin
13 -1000000 -1000000

-1000000 0

0 -1000000

999417 840

999781 33421

999994 131490

999993 998865

962080 999911

629402 999973

378696 999988

53978 999788

25311 999558

6082 999282

1565 998489
stdout
23547598153913.984405517578125