Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

const double EPS = 1e-8;

#define curr(G, i) G[i%n]
#define next(G, i) G[(i+1)%n]

typedef complex<double> P;
typedef vector<P> triangle;
typedef vector<P> Poly;
struct L : public vector<P>{
    L(const P &a, const P &b){
        push_back(a), push_back(b);
    }
};

namespace std {
  bool operator < (const P& a, const P& b) {
    return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
  }
}

double cross(const P &a, const P &b){
    return imag(conj(a)*b);
}

double dot(const P &a, const P &b){
    return real(conj(a)*b);
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > 0) return +1;
    if(cross(b,c) < 0) return -1;
    if(dot(b,c) < 0) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

triangle makeTriangle(const P &a, const P &b, const P &c){
    triangle res(3);
    res[0] = a;
    res[1] = b;
    res[2] = c;
    return res;
}

bool containment(const triangle &tri, const P &p){
    return ccw(tri[0], tri[1], p) >=0 && ccw(tri[1], tri[2], p) >=0 && ccw(tri[2], tri[0], p) >=0;
}

bool triangeJudge(int i, int j, int k, const Poly &G){
    if(ccw(G[i], G[j], G[k])<=0) return false;
    triangle tri = makeTriangle(G[i], G[j], G[k]);
    for (int l=0;l<G.size();l++){
        if(l != i && l != j && l != k){
            if(containment(tri, G[l])) return false;
        }
    }
    return true;
}

vector<triangle> triangulation(Poly &G){
    vector<triangle> res;
    int n = G.size();
    vector<int> l, r;
    for (int i=0;i<n;i++){
        l.push_back((i-1+n)%n);
        r.push_back((i+1+n)%n);
    }

    int i = n-1;
    while(res.size() < n-2){
        i = r[i];
        if(triangeJudge(l[i], i, r[i], G)){
            res.push_back(makeTriangle(G[l[i]], G[i], G[r[i]]));
            l[ r[i] ] = l[i];
            r[ l[i] ] = r[i];
        }
    }
    return res;
}

double area(vector<P> &G){
    int n = G.size();
    double S = 0;
    for (int i=0;i<n;i++){
        P p = curr(G, i);
        P q = next(G, i);
        S += (1.0/2)*cross(p, q);
    }
    return S;
}

double arcArea(P &p, P &q, double r){
    double theta = arg(q) - arg(p);
    if(theta < 0) theta += 2.0 * M_PI;
    return (1.0/2)*r*r*(theta - sin(theta));
}

vector<P> crossCircleLine(P p1, P p2, double r){
    vector<P> res;

    double a = p2.imag() - p1.imag();
    double b = -(p2.real() - p1.real());
    double c = p1.real()*p2.imag() - p2.real()*p1.imag();
    if ( ((a*a + b*b)*r*r - c*c) < 0 )  return res;
    double x1 = (a*c - b*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double y1 = (b*c + a*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double x2 = (a*c + b*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double y2 = (b*c - a*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    P q1(x1, y1);
    P q2(x2, y2);

    if (norm(q1-p1) > norm(q2-p1)) swap(q1, q2);
    if (dot(q1- p1, q1 - p2) <= EPS) res.push_back(q1);
    if (dot(q2- p1, q2 - p2) <= EPS) res.push_back(q2);

    return res;
}

double intersectionCicleTriangle(triangle &T, double r){

    P z(0, 0);
    bool crossing = false;
    for(int i=0;i<3;i++){
        vector<P> crossed = crossCircleLine(T[i], T[(i+1)%3], r);
        if (crossed.size() != 0){
            crossing = true;
            break;
        }
    }
    if(!crossing && norm(T[0]) > r*r + EPS && containment(T, z)) return M_PI*r*r;

    vector<P> Time;
    vector<P> Arc;
    vector<bool> type;
    int inOnOut;
    for(int i=0;i<3;i++){
        inOnOut = inOnOutCircle(T[i], r);
        cout << inOnOut << endl;
        vector<P> crossed = crossCircleLine(T[i], T[(i+1)%3], r);
        if(inOnOut == 0){
            Time.push_back(T[i]);
            if(crossed.size() == 1){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(true);
            }
        }else if(inOnOut == 1){
            Time.push_back(T[i]);
            P tt(-T[i].imag(), T[i].real());
            P p1 = T[(i+2)%3] - T[i];
            P p2 = T[(i+1)%3] - T[i];
            if(cross(tt, p1) > EPS && cross(tt, p2) <= EPS){
                Arc.push_back(T[i]);
                type.push_back(true);
            }
            if(cross(tt, p1) <= EPS && cross(tt, p2) > EPS){
                Arc.push_back(T[i]);
                type.push_back(false);
            }
        }else{
            if(crossed.size() == 1){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(false);
            }else if(crossed.size() == 2){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(false);
                Time.push_back(crossed[1]);
                Arc.push_back(crossed[1]);
                type.push_back(true);
            }
        }
    }
/*
    cout << "Time: " << endl;
    for(int i=0;i<Time.size();i++){
        cout << Time[i].real() << " " << Time[i].imag() << endl;
    }
    cout << "Arc: " << endl;
    for(int i=0;i<Arc.size();i++){
        cout << Arc[i].real() << " " << Arc[i].imag() << endl;
    }
    cout << "type: " << endl;
    for(int i=0;i<type.size();i++){
        cout << type[i] << endl;
    }
*/
    double S = 0;
    S += area(Time);
    if(Arc.size() != 0){
        if(!type[0]){
            for(int i=0;i<(Arc.size()/2)-1;i++){
                S += arcArea(Arc[2*i+1], Arc[2*i+2],r);
            }
            S += arcArea(Arc[Arc.size()-1], Arc[0],r);
        }else{
            for(int i=0;i<Arc.size()/2;i++){
                S += arcArea(Arc[2*i], Arc[2*i+1], r);
            }
        }
    }

    return S;
}

double intersectionOfCircleAndPolygon(Poly &G, double r){
    vector<triangle> ears = triangulation(G);
    double S = 0;
    for (int i=0;i<ears.size();i++){
        S += intersectionCicleTriangle(ears[i], r);
    }
    return S;

}

int main(){
    int n;
    double r, x, y;
    cin >> n >> r;
    Poly G;
    for (int i=0;i<n;i++){
        P p;
        cin >> p.real() >> p.imag();
        G.push_back(p);
    }

    printf("%.12f\n", intersectionOfCircleAndPolygon(G, r));

    return 0;
}

Compiler output:
a.cc: In function 'double intersectionCicleTriangle(triangle&, double)':
a.cc:152:19: error: 'inOnOutCircle' was not declared in this scope
  152 |         inOnOut = inOnOutCircle(T[i], r);
      |                   ^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:239:13: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'double')
  239 |         cin >> p.real() >> p.imag();
      |         ~~~ ^~ ~~~~~~~~
      |         |            |
      |         |            double
      |         std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42,
                 from a.cc:1:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  219 |       operator>>(float& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:219:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  223 |       operator>>(double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:223:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'double&' to an rvalue of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  227 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:227:7: note:   conversion of argument 1 would be ill-formed:
a.cc:239:22: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type 'double'
  239 |         cin >> p.real() >> p.imag();
      |                ~~~~~~^~
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:25: note:   no known conversion for argument 1 from 'double' to 'void*&'
  328 |       operator>>(void*& __p)
      |                  ~~~~~~~^~~
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:36: note:   no known conversion for argument 1 from 'double' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'}
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]'
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:32: note:   no known conversion for argument 1 from 'double' to 'std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/istream:133:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_