Language: C++

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <complex>

using namespace std;

typedef complex<double> P;

double EPS = 1e-8;

typedef struct {
	P s,e;
	double h;
}RECT;

void P_cin(P& p){
	double x,y;
	cin >>x >> y;
	p.real(x); p.imag(y);
}
double dot(P& a,P& b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); } 

bool is_intersected_ls(P a1, P a2, P b1, P b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

double distance_lp(P& s,P& e,P &p){
	if(dot(e-s,p-s) < EPS) return abs(p-s); //_sÆÌ£
	if(dot(s-e,p-e) < EPS) return abs(p-e); //_eÆÌ£
	return abs(cross(e-s,p-s)) / abs(e-s); //_Æ¼üÆÌ£
}

bool is_contained(P& a,P& b,P& p){
	return (a.real() <= p.real() && p.real() <= b.real()) &&
		(a.imag() <= p.imag() && p.imag() <= b.imag());
}

double distance_rl(P& a,P& b,P& s,P& e){
	if(is_contained(a,b,s) || is_contained(a,b,e))
		return 0.0; //R[X©Ìª ÉüÁÄé

	double len = 1e10;
	P rectP[] = {a,P(a.real(),b.imag()),b,P(b.real(),a.imag())};
	for(int i = 0; i < 4; i++){
		if(is_intersected_ls(rectP[i],rectP[(i+1)%4],s,e)) return 0.0; //ð·µÄ¢é
		len = min(len,distance_lp(rectP[i],rectP[(i+1)%4],s));
		len = min(len,distance_lp(rectP[i],rectP[(i+1)%4],e));
		len = min(len,distance_lp(e,s,rectP[i]));
	}

	return len;
}

double distance(RECT &r,P& s,P& e){
	double len = distance_rl(r.s,r.e,s,e);
	if(len <= r.h) return len; //cÉ¢
	return (r.h + len * len / r.h) / 2; //cÌûªá¢ÌÅvZ·é
}

int N;

void solve(){

	P s,e;
	P_cin(s);
	P_cin(e);

	vector<RECT> rects(N);
	for(int i = 0; i < N; i++){
		RECT &r = rects[i];
		P_cin(r.s);
		P_cin(r.e);
		cin >> r.h;
	}
	
	double ans = 1e10;
	for(int i = 0; i < N; i++){
		ans = min(ans,distance(rects[i],s,e));
	}

	cout << ans << endl;
}

int main()
{
	while(cin >> N,N){
		solve();
	}

	return 0;
}

Compiler output:
a.cc: In function 'bool is_intersected_ls(P, P, P, P)':
a.cc:30:20: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   30 |   return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
      |                  ~~^~~
a.cc:27:17: note:   initializing argument 1 of 'double cross(P&, P&)'
   27 | double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); }
      |              ~~~^
a.cc:30:42: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   30 |   return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
      |                                        ~~^~~
a.cc:27:17: note:   initializing argument 1 of 'double cross(P&, P&)'
   27 | double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); }
      |              ~~~^
a.cc:31:20: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   31 |          ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
      |                  ~~^~~
a.cc:27:17: note:   initializing argument 1 of 'double cross(P&, P&)'
   27 | double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); }
      |              ~~~^
a.cc:31:42: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   31 |          ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
      |                                        ~~^~~
a.cc:27:17: note:   initializing argument 1 of 'double cross(P&, P&)'
   27 | double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); }
      |              ~~~^
a.cc: In function 'double distance_lp(P&, P&, P&)':
a.cc:35:17: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   35 |         if(dot(e-s,p-s) < EPS) return abs(p-s); //_sÆÌ£
      |                ~^~
a.cc:26:15: note:   initializing argument 1 of 'double dot(P&, P&)'
   26 | double dot(P& a,P& b){ return a.real() * b.real() + a.imag() * b.imag(); }
      |            ~~~^
a.cc:36:17: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   36 |         if(dot(s-e,p-e) < EPS) return abs(p-e); //_eÆÌ£
      |                ~^~
a.cc:26:15: note:   initializing argument 1 of 'double dot(P&, P&)'
   26 | double dot(P& a,P& b){ return a.real() * b.real() + a.imag() * b.imag(); }
      |            ~~~^
a.cc:37:27: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'std::complex<double>'
   37 |         return abs(cross(e-s,p-s)) / abs(e-s); //_Æ¼üÆÌ£
      |                          ~^~
a.cc:27:17: note:   initializing argument 1 of 'double cross(P&, P&)'
   27 | double cross(P& a,P& b){ return a.real() * b.imag() - a.imag() * b.real(); }
      |              ~~~^