SHARE
TWEET

Help Codeforces

a guest Jan 20th, 2016 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <climits>
  5. #include <iomanip>
  6. #define PI 3.14159265358979323846
  7. using namespace std;
  8. typedef struct{double x,y;} punct; //a point
  9. punct P,varf[100000];
  10. int N,i;
  11. double rez,R,r;
  12. double dist(punct A,punct B) //distance between 2 points A and B
  13. {
  14.     return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));
  15. }
  16. double intersectie(punct A,punct B,punct M)
  17. {
  18.     double x=0,y=0,mMO=0,mAB=0;
  19.     mAB=(B.y-A.y)/(B.x-A.x); //m from the straight line equation for side
  20.     mMO=(A.x-B.x)/(B.y-A.y); //m for the distance from M to AB
  21.     x=(mMO*M.x-mAB*A.x+A.y-M.y)/(mMO-mAB);  // after equations solved, that's the x for O(the end of the perpendicular segment)
  22.     y=mMO*(x-M.x)+M.y; //y for point O
  23.     punct O;//the point O
  24.     O.x=x;
  25.     O.y=y;
  26.     if((A.x<=x&&x<=B.x)||(A.x>=x&&x>=B.x))//if O is on AB
  27.         return dist(O,M);
  28.     else
  29.         return min(dist(M,A),dist(M,B));
  30. }
  31. int main()
  32. {
  33.     cin>>N>>P.x>>P.y;
  34.     for(i=1;i<=N;i++)
  35.     {
  36.         cin>>varf[i].x>>varf[i].y; //reading
  37.     }
  38.     r=90000000000000; //min distance to a side of the poligon
  39.     for(i=1;i<=N;i++)
  40.     {
  41.         R=max(R,dist(P,varf[i])); //max distance from P to vertices
  42.         r=min(r,intersectie(varf[i],varf[i%N+1],P));
  43.     }
  44.     rez=PI*pow(R,2)-PI*pow(r,2); //area of big circle - area of little circle
  45.     cout<<setprecision(20)<<rez; //printing the result with precision of 20
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top