Language: C++

#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
#include <queue>
#define X real()
#define Y imag()
#define EPS (1e-10)
#define INF (1e9)
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;
typedef vector<P> Poly;
typedef vector<int> vi;
typedef pair<int,int> pii;


namespace std{
  bool operator<(const P& a, const P& b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
  bool cmp_y(const P &a, const P &b){
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
}

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}
  
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b-a) + EPS < abs(c-a) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  if(ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
     ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0) return true;
  return false;
}

double p_to_s_dist(P a, L s){
  if(dot(s.second-s.first,a-s.first) >= 0 && dot(s.first-s.second,a-s.second) >= 0){
    return abs(cross(s.first-s.second,a-s.second))/abs(s.first-s.second);
  }
  return min(abs(a-s.first), abs(a-s.second));
}

double s_to_s_dist(L a, L b){
  if(is_cross(a,b)) return 0;
  return min(min(p_to_s_dist(a.first,b),p_to_s_dist(a.second,b)),
	     min(p_to_s_dist(b.first,a),p_to_s_dist(b.second,a)));
}


Poly convex_hull(Poly v){
  int n = v.size(), k = 0;
  sort(v.begin(), v.end(), cmp_y);
  Poly r(2*n);
  for(int i = 0; i < n; i++){
    while(k>1 && cross(r[k-1]-r[k-2],v[i]-r[k-2]) < -EPS)k--;
    r[k++] = v[i];
  }
  for(int i = n-2, t = k; i >= 0; i--){
    while(k>t && cross(r[k-1]-r[k-2],v[i]-r[k-2]) < -EPS)k--;
    r[k++] = v[i];
  }
  r.resize(k-1);
  return r;
}

int in_poly(P a, Poly p){
  int n = p.size(), c = 0;
  p.push_back(p[0]);
  for(int i = 0; i < n; ++i){
    P s = p[i]-a, t = p[i+1]-a;
    if(!ccw(s,t,P(0,0))) return 1;//??????
    if(s.Y > t.Y + EPS) swap(s,t);
    if((s.Y*t.Y < 0 || (s.Y*t.Y < EPS && t.Y > EPS)) && cross(s,t) < EPS) ++c;
  }
  if(c%2) return 2;//?????¨
  return 0;//?????¨
}

double poly_to_poly_dist(Poly a, Poly b){
  int n = a.size(), m = b.size();
  double d = INF;
  for(int i = 0; i < m; ++i)
    if(in_poly(b[i],a)) return 0;

  for(int i = 0; i < n; ++i){
    if(in_poly(a[i],b)) return 0;
    for(int j = 0; j < m; ++j){
      L sa = L(a[i],a[(i+1)%n]), sb = L(b[j],b[(j+1)%m]);
      if(is_cross(sa,sb)) return 0;
      d = min(d, s_to_s_dist(sa,sb));
    }
  }
  return d;
}

double p_to_poly_dist(P a, Poly p){
  if(in_poly(a,p)) return 0;
  int n = p.size();
  double d = INF;
  for(int i = 0; i < n; ++i)
    d = min(d, p_to_s_dist(a,L(p[i],p[(i+1)%n])));
  return d;
}

double solve(int N, vector<Poly> p, vector<double> H, P s, P t, double theta, double f){
  vector<Poly> shade;
  for(int i = 0; i < N; ++i){
    int n = p[i].size();
    for(int j = 0; j < n; ++j){
      p[i].push_back(p[i][j]-polar(H[i]/tan(f),theta));
    }
    shade.push_back(convex_hull(p[i]));
  }
  vector< vector<double> > dist(N+2, vector<double>(N+2,INF));
  dist[0][1] = abs(s-t);
  dist[1][0] = dist[0][1];
  dist[0][0] = 0;
  dist[1][1] = 0;
  for(int i = 0; i < N; ++i){
    dist[0][i+2] = p_to_poly_dist(s,shade[i]);
    dist[i+2][0] = dist[0][i+2];
    dist[1][i+2] = p_to_poly_dist(t,shade[i]);
    dist[i+2][1] = dist[1][i+2];
  }

  for(int i = 0; i < N; ++i){
    dist[i+2][i+2] = 0;
    for(int j = i+1; j < N; ++j){
      dist[i+2][j+2] = poly_to_poly_dist(shade[i],shade[j]);
      dist[j+2][i+2] = dist[i+2][j+2];
    }
  }
  for(int k = 0; k < N+2; ++k){
    for(int i = 0; i < N+2; ++i){
      for(int j = 0; j < N+2; ++j){
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist[0][1];
}

int main(){
  int N;
  while(cin >> N, N){
    int nv;
    double x, y;
    vector<double> H(N);
    vector<Poly> p(N);
    for(int i = 0; i < N; ++i){
      cin >> nv >> H[i];
      for(int j = 0; j < nv; ++j){
	cin >> x >> y;
	p[i].push_back(P(x,y));
      }
    }
    double theta, f, pi = acos(-1);
    cin >> theta >> f;
    theta = theta/180*pi;
    f = f/180*pi;
    P s, t;
    cin >> x >> y;
    s = P(x, y);
    cin >> x >> y;
    t = P(x, y);
    printf("%.10lf\n",solve(N, p, H, s, t, theta, f));
  }
  return 0;
}

Compiler output:
a.cc: In function 'Poly convex_hull(Poly)':
a.cc:67:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   67 |   sort(v.begin(), v.end(), cmp_y);
      |   ^~~~
      |   sqrt