Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<complex>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back

typedef complex<double> P;
const double eps = 1e-10;

#define EQ(a,b) abs(a-b) < eps
#define RIGHT 1
#define LEFT -1
 
void op(vector<P> &a){
  rep(i,a.size())cout << a[i];cout << endl;
}

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}
 
bool is_intersect_ll(P a1,P a2,P b1,P b2){
  return !EQ( cross(a1-a2,b1-b2),0.0);
}

P intersection_ll(P a1,P a2,P b1,P b2){
  P a=a2-a1,b=b2-b1;
  return a1 + a*cross(b,b1-a1)/cross(b,a);
}

double isp(P a,P b,P c){
  return abs(a-c)+abs(b-c) < abs(a-b)+eps;
}
 
int ccw(P a,P b){
  if (cross(a,b)<0 )return RIGHT;
  else if ( cross(a,b)>0)return LEFT;
  return 2;
}

vector<P> Convex_Cut(vector<P> &in,int n, P a1,P a2,int dir){
  vector<P> ret;
  rep(i,n){
    P now = in[i],next=in[(i+1)%n];
    if ( ccw(a1-a2,now-a2)==dir)ret.push_back(now);
    if ( ccw(a1-a2,now-a2)*ccw(a1-a2,next-a2)< 0 &&
	 is_intersect_ll(a1,a2,now,next))
      ret.push_back( intersection_ll(a1,a2,now,next));
  }
  return ret;
}

double Polygon_Area(vector<P> &a,int n){
  double sum = 0;
  for(int i=0;i<n;i++){
    sum += (a[i%n].real()-a[(i+1)%n].real())*(a[i%n].imag()+a[(i+1)%n].imag());
  }
  if (sum < 0)sum*=-1;
  return (double)(sum/2.0);
}

vector<P> cut(int n,int bit,vector<P>&in){
  vector<P> tar;
  tar.pb(P(-100,-100));
  tar.pb(P(-100,1000));
  tar.pb(P(1000,1000));
  tar.pb(P(1000,-100));
  rep(i,n){
    int dir=RIGHT;
    if ((bit&(1<<i)) != 0)dir=LEFT;
    tar=Convex_Cut(tar,tar.size(),in[i],in[(i+1)%n],dir);
  }
  return tar;
}

class pt{
public:
  int num;
  double ang;
  bool operator<(const pt & a)const{
    return ang < a.ang;
  }
};


bool is_in(vector<P> &in,P a){
  int cnt =0;
  int n = in.size();
  rep(i,n){
    P cur = in[i]-a,next=in[(i+1)%n]-a;
    if (cur.imag() > next.imag())swap(cur,next);
    if (cur.imag()<0 && 0<=next.imag() &&
	cross(next,cur)>=0)cnt++;
    if (isp(in[i],in[(i+1)%n],a))return true;
  }
  if (cnt %2 == 1)return true;
  else return false;
}

P get_random_point(vector<P> &poly){
  P mid=(poly[0]+poly[1]);
  mid/=2;
  P ret=poly[2]-mid;
  ret/=10000;
  ret+=mid;
  //op(poly);
  //cout << ret << endl;
  assert(is_in(poly,ret));
  return ret;
}

bool check(vector<P> &poly,const vector<P> &in,vector<int>&ord){
  vector<pt> a;
  P b=get_random_point(poly);
  rep(i,in.size())a.pb((pt){i+1,arg(in[i]-b)});

  sort(a.begin(),a.end());
  //rep(i,a.size())cout<< a[i].num << " "<< a[i].ang << endl;
  int mod=a.size();
  rep(i,a.size()){
    if (a[i].num != ord[0])continue;
    rep(j,a.size()){
      if (a[(i+j)%mod].num != ord[j])return false;
    }
    return true;
  }
  return false;
}

bool caninf(vector<P> &in){
  int n=in.size();
  vector<P> tar;
  tar.pb(P(-100,-100));
  tar.pb(P(-100,1000));
  tar.pb(P(1000,1000));
  tar.pb(P(1000,-100));
  rep(i,in.size()){
    rep(j,tar.size()){
      P mid=in[i]+in[(i+1)%n];
      mid/=2;
      if (isp(tar[j],tar[(j+1)%tar.size()],mid)){
	return !is_intersect_ll(in[i],in[(i+n-1)%n],
			       in[(i+1)%n],in[(i+2)%n]);
      }
    }
  }
  return false;
}

void solve(int n,vector<P> &in,vector<int> &ord){
  double ans=0;
  bool isinf=false;
  rep(i,(1<<n)){
    vector<P> tmp=cut(n,i,in);
    double area=Polygon_Area(tmp,tmp.size());
    if (area < eps )continue;
    if (!check(tmp,in,ord))continue;
    //op(tmp);
    if (caninf(tmp)){
      isinf=true;
      break;
    }
    ans+=area;
  }

  if (isinf){
    printf("Infinity\n");
  }else if (ans < 1e-5){
    printf("No area\n");
  }else {
    printf("%.5lf\n",ans);
  }
}

main(){
  int tc=1;
  int n;
  while(cin>>n && n){
    vector<int>ord(n);
    vector<P> in(n);
    rep(i,n){
      cin>>in[i].real()>>in[i].imag();
    }
    rep(i,n)cin>>ord[i];
    cout << "Case "<< tc++ << ": ";
    solve(n,in,ord);
  }
  return false;
}

Compiler output:
a.cc: In function 'P get_random_point(std::vector<std::complex<double> >&)':
a.cc:111:3: error: 'assert' was not declared in this scope
  111 |   assert(is_in(poly,ret));
      |   ^~~~~~
a.cc:5:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    4 | #include<complex>
  +++ |+#include <cassert>
    5 | using namespace std;
a.cc: At global scope:
a.cc:178:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  178 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:185:10: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'double')
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'double&' to an rvalue of type 'double'
  185 |       cin>>in[i].real()>>in[i].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:185:22: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type 'double'
  185 |       cin>>in[i].real()>>in[i].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>>(__io