Problem:
Problem I:
Roads in a City
Roads in a city play important roles in development of the city. Once a road is built, people start their
living around the road. A broader road has a bigger capacity, that is, people can live on a wider area
around the road.
Interstellar Conglomerate of Plantation and Colonization (ICPC) is now planning to develop roads on
a new territory. The new territory is a square and is completely clear. ICPC has already made several
plans, but there are some difficulties in judging which plan is the best.
Therefore, ICPC has collected several great programmers including you, and asked them to write programs
that compute several metrics for each plan. Fortunately your task is a rather simple one. You are asked to
compute the area where people can live from the given information about the locations and the capacities
of the roads.
The following figure shows the first plan given as the sample input.
Figure 1: The first plan given as the sample input
Input
The input consists of a number of plans. The first line of each plan denotes the number
n
of roads
(
n
≤ 50), and the following
n
lines provide five integers
x
1
,
y
1
,
x
2
,
y
2
, and
r
, separated by a space.
(
x
1
,
y
1
) and (
x
2
,
y
2
) denote the two endpoints of a road (-15 ≤
x
1
,
y
1
,
x
2
,
y
2
≤ 15), and the value
r
denotes the capacity that is represented by the maximum distance from the road where people can live
(
r
≤ 10).
The end of the input is indicated by a line that contains only a single zero.
The territory is located at -5 ≤
x
,
y
≤ 5. You may assume that each road forms a straight line segment
and that any lines do not degenerate.
Output
Print the area where people can live in one line for each plan. You may print an arbitrary number of
digits after the decimal points, provided that difference from the exact answer is not greater than 0.01.
Sample Input
2
0 -12 0 0 2
0 0 12 0 2
0
Output for the Sample Input
39.14159

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <stdlib.h>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back


struct Vec2{
    double x;
    double y;
    Vec2(double X, double Y) : x(X), y(Y) {}
    bool operator==(const Vec2& rhs) const{
        return x==rhs.x ? y==rhs.y : false;
    }

    bool operator!=(const Vec2& rhs) const{
        return (*this)==rhs ? false: true;
    }
    Vec2 operator=(const Vec2& rhs){
        x=rhs.x; y=rhs.y;
        return (*this);
    }
    Vec2 operator+(const Vec2& rhs) const{
        return Vec2(this->x+rhs.x, this->y+rhs.y);
    }
    Vec2 operator-(const Vec2& rhs) const{
        return Vec2(this->x-rhs.x, this->y-rhs.y);
    }
    Vec2 operator*(const double &rhs) const{
        return Vec2(this->x*rhs,this->y*rhs);
    }

    Vec2 operator/(const double &rhs) const{
        assert(rhs>0);
        return Vec2(this->x/rhs,this->y/rhs);
    }
    
    double operator*(const Vec2 &rhs) const{
        return this->x*rhs.x+this->y*rhs.y;
    }
    
};
double length(const Vec2 &a){
    return sqrt(a*a);
}

Vec2 normalize(const Vec2 &a){
    double len=length(a);
    return len>0 ? a/len : a;
}

Vec2 sui(const Vec2 &a){
    Vec2 aa=normalize(a);
    return Vec2(aa.y,-aa.x);
}

const double OUT=5000000;

double given_x(Vec2 a, Vec2 b, double xx, bool senbun=true);
double given_y(Vec2 a, Vec2 b, double yy, bool senbun=true);

struct circle{
    Vec2 mid;
    double r;
    circle(Vec2 mid_, double r_):mid(mid_),r(r_){}
    bool inside(Vec2 p) const{
        return length(p-mid)<r;
    }
};

struct rectangle{
    Vec2 a;
    Vec2 b;
    double r;
    vector<Vec2> corners;
    rectangle(Vec2 a_, Vec2 b_, double r_) : a(a_), b(b_), r(r_){
        Vec2 s=sui(b-a)*r;
        corners.pb(a+s);
        corners.pb(a-s);
        corners.pb(b-s);
        corners.pb(b+s);
    }
    void print() const{
        cout<<"rectangle is ";
        for(auto e: corners) cout<<e.x<<' '<<e.y<<", ";
        cout<<endl;
    }
};

struct square{
    Vec2 mid;
    double len;
    vector<Vec2> corners;
    double xl,xu,yl,yu;
    square(Vec2 mid_,double len_):mid(mid_),len(len_) ,xl(mid.x-len/2), xu(mid.x+len/2), yl(mid.y-len/2), yu(mid.y+len/2) {
        corners.pb(Vec2(xl,yl));
        corners.pb(Vec2(xu,yl));
        corners.pb(Vec2(xu,yu));
        corners.pb(Vec2(xl,yu));
    }
    bool inside(Vec2 p) const{
        if(abs(p.x-mid.x)>len/2) return false;
        if(abs(p.y-mid.y)>len/2) return false;
        return true;
    }

    int judge(const circle &c) const{
        bool memo=c.inside(corners[0]);
        REP(i,1,4) if(memo!=c.inside(corners[i])) return 0; //0は混在
        if(memo) return 1; // 1は完全に含まれている
        if(length(this->mid-c.mid)<c.r+len/2) return 0;
        return -1;
    }

    int judge(const rectangle &c) const;
    void print() const{
        cout<<"square is ";
        for(auto e: corners) cout<<e.x<<' '<<e.y<<", ";
        cout<<endl;
    }
};



double given_x(Vec2 a, Vec2 b, double xx, bool senbun){
    if(senbun && a.x>xx && b.x>xx) return OUT;
    if(senbun && a.x<xx && b.x<xx) return OUT;
    if(a.x==xx) return a.y;
    if(b.x==xx) return b.y;
    double Y=b.y-a.y, X=b.x-a.x, XX=xx-a.x;
    if(!X) return a.y+Y/2;
    return a.y+Y*XX/X;
}

double given_y(Vec2 a, Vec2 b, double yy, bool senbun){
    if(senbun && a.y>yy && b.y>yy) return OUT;
    if(senbun && a.y<yy && b.y<yy) return OUT;
    if(a.y==yy) return a.x;
    if(b.y==yy) return b.x;
    double Y=b.y-a.y, X=b.x-a.x, YY=yy-a.y;
    if(!Y) return a.x+X/2;
    return a.x+X*YY/Y;
}
bool cross(square s, Vec2 a, Vec2 b){
    if(a.x<s.xl && b.x<s.xl) return false;
    if(a.x>s.xu && b.x>s.xu) return false;
    if(a.y<s.yl && b.y<s.yl) return false;
    if(a.y>s.yu && b.y>s.yu) return false;
    if(a.x==b.x) return true;
    if(a.y==b.y) return true;
    double XL=given_x(a,b,s.xl);
    if(s.yl<=XL && XL<=s.yu) return true;
    double XU=given_x(a,b,s.xu);
    if(s.yl<=XU && XU<=s.yu) return true;
    double YL=given_y(a,b,s.yl);
    if(s.xl<=YL && YL<=s.xu) return true;
    double YU=given_y(a,b,s.yu);
    if(s.xl<=YU && YU<=s.xu) return true;
    return false;
}

int square::judge(const rectangle &c) const{
    rep(i,4) if(this->inside(c.corners[i])) return 0;
    rep(i,4) if(cross((*this),c.corners[i],c.corners[(i+1)%4])) return 0;
    double big=OUT,small=OUT;
    rep(i,4) {
        auto tmp=given_x(c.corners[i], c.corners[(i+1)%4], xl);
        if(c.corners[i].x!=xl || c.corners[(i+1)%4].x!=xl) {
            if(tmp!=OUT){
                if(tmp>=yu) big=tmp;
                if(tmp<=yl) small=tmp;
            }
        }
    }
    /*this->print();
    c.print();
    cout<<big<<' '<<small<<endl;*/
    if(big==OUT) return -1;
    if(small==OUT) return -1;
    return 1;
}


double smallest=(1e-8);

struct one_question{
    ll N,R,C; 
    vector<rectangle> rec;
    vector<circle> cir;
    
    one_question(ll N_) :N(N_){
        rep(i,N){
            double a,b,c,d,r; cin>>a>>b>>c>>d>>r;
            Vec2 A(a,b), B(c,d);
            cir.pb(circle(A,r));
            if(A!=B){
                cir.pb(circle(B,r));
                rec.pb(rectangle(A,B,r));
            }
        }
        R=rec.size(); C=cir.size();
    }
    double Solve(const square& s, vec rec_memo, vec cir_memo){
        double full=s.len*s.len;
        if(full<=smallest) return full/2;
        bool nothing=true;
        rep(i,R) if(!rec_memo[i]){
            rec_memo[i]=s.judge(rec[i]);
            if(rec_memo[i]==1) return full;
            if(rec_memo[i]==0) nothing=false;
        }
        rep(i,C) if(!cir_memo[i]){
            cir_memo[i]=s.judge(cir[i]);
            if(cir_memo[i]==1) return full;
            if(cir_memo[i]==0) nothing=false;
        }
        if(nothing) return 0;
        double ret=0;
        rep(i,4){
            square tmp((s.mid+s.corners[i])/2,s.len/2);
            ret+=Solve(tmp,rec_memo,cir_memo);
        }
        return ret;

    }
    double ans(){
        square start(Vec2(0,0),10);
        vec rec_memo(R,0);
        vec cir_memo(C,0);
        return Solve(start,rec_memo,cir_memo);
    }

};
     

int main(){
    vector<double> ret;
    while(true){
        ll n; cin>>n;
        if(!n) break;
        one_question tmp(n);
        ret.pb(tmp.ans());
    }
    for(auto e: ret) cout<<setprecision(8)<<e<<endl;
}
accuracy: 1
time_ms: 1870
memory_kb: 3616
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#include <stdlib.h>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const ll MAXINF=9223372036854775806;
const double DEL=1e-7;
const double PI=3.14159265359;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());





struct Vec2{
    double x;
    double y;
    Vec2(double X, double Y) : x(X), y(Y) {}
    Vec2(PD a):x(a.first), y(a.second) {}
    bool operator==(const Vec2& rhs) const{
        return x==rhs.x ? y==rhs.y : false;
    }

    bool operator!=(const Vec2& rhs) const{
        return (*this)==rhs ? false: true;
    }
    Vec2 operator=(const Vec2& rhs){
        x=rhs.x; y=rhs.y;
        return (*this);
    }
    Vec2 operator+(const Vec2& rhs) const{
        return Vec2(this->x+rhs.x, this->y+rhs.y);
    }
    Vec2 operator-(const Vec2& rhs) const{
        return Vec2(this->x-rhs.x, this->y-rhs.y);
    }
    Vec2 operator*(const double &rhs) const{
        return Vec2(this->x*rhs,this->y*rhs);
    }

    Vec2 operator/(const double &rhs) const{
        assert(rhs>0);
        return Vec2(this->x/rhs,this->y/rhs);
    }
    double operator*(const Vec2 &rhs) const{
        return this->x*rhs.x+this->y*rhs.y;
    }
    
};
double length(const Vec2 &a){
    return sqrt(a*a);
}

Vec2 normalize(const Vec2 &a){
    double len=length(a);
    return len>0 ? a/len : a;
}

Vec2 sui(const Vec2 &a){
    Vec2 aa=normalize(a);
    return Vec2(aa.y,-aa.x);
}

const double OUT=5000000;

double given_x(Vec2 a, Vec2 b, double xx, bool senbun=true);
double given_y(Vec2 a, Vec2 b, double yy, bool senbun=true);

struct circle{
    Vec2 mid;
    double r;
    circle(Vec2 mid_, double r_):mid(mid_),r(r_){}
    bool inside(Vec2 p) const{
        return length(p-mid)<r;
    }
};

struct rectangle{
    Vec2 a;
    Vec2 b;
    double r;
    vector<Vec2> corners;
    rectangle(Vec2 a_, Vec2 b_, double r_) : a(a_), b(b_), r(r_){
        Vec2 s=sui(b-a)*r;
        corners.pb(a+s);
        corners.pb(a-s);
        corners.pb(b-s);
        corners.pb(b+s);
    }
    void print() const{
        cout<<"rectangle is ";
        for(auto e: corners) cout<<e.x<<' '<<e.y<<", ";
        cout<<endl;
    }
};

struct square{
    Vec2 mid;
    double len;
    vector<Vec2> corners;
    double xl,xu,yl,yu;
    square(Vec2 mid_,double len_):mid(mid_),len(len_) ,xl(mid.x-len/2), xu(mid.x+len/2), yl(mid.y-len/2), yu(mid.y+len/2) {
        corners.pb(Vec2(xl,yl));
        corners.pb(Vec2(xu,yl));
        corners.pb(Vec2(xu,yu));
        corners.pb(Vec2(xl,yu));
    }
    bool inside(Vec2 p) const{
        if(abs(p.x-mid.x)>len/2) return false;
        if(abs(p.y-mid.y)>len/2) return false;
        return true;
    }

    int judge(const circle &c) const{
        bool memo=c.inside(corners[0]);
        REP(i,1,4) if(memo!=c.inside(corners[i])) return 0; //0は混在
        if(memo) return 1; // 1は完全に含まれている
        if(length(this->mid-c.mid)<c.r+len/2) return 0;
        return -1;
    }

    int judge(const rectangle &c) const;
    void print() const{
        cout<<"square is ";
        for(auto e: corners) cout<<e.x<<' '<<e.y<<", ";
        cout<<endl;
    }
};



double given_x(Vec2 a, Vec2 b, double xx, bool senbun){
    if(senbun && a.x>xx && b.x>xx) return OUT;
    if(senbun && a.x<xx && b.x<xx) return OUT;
    if(a.x==xx) return a.y;
    if(b.x==xx) return b.y;
    double Y=b.y-a.y, X=b.x-a.x, XX=xx-a.x;
    if(!X) return a.y+Y/2;
    return a.y+Y*XX/X;
}

double given_y(Vec2 a, Vec2 b, double yy, bool senbun){
    if(senbun && a.y>yy && b.y>yy) return OUT;
    if(senbun && a.y<yy && b.y<yy) return OUT;
    if(a.y==yy) return a.x;
    if(b.y==yy) return b.x;
    double Y=b.y-a.y, X=b.x-a.x, YY=yy-a.y;
    if(!Y) return a.x+X/2;
    return a.x+X*YY/Y;
}
bool cross(square s, Vec2 a, Vec2 b){
    if(a.x<s.xl && b.x<s.xl) return false;
    if(a.x>s.xu && b.x>s.xu) return false;
    if(a.y<s.yl && b.y<s.yl) return false;
    if(a.y>s.yu && b.y>s.yu) return false;
    if(a.x==b.x) return true;
    if(a.y==b.y) return true;
    double XL=given_x(a,b,s.xl);
    if(s.yl<=XL && XL<=s.yu) return true;
    double XU=given_x(a,b,s.xu);
    if(s.yl<=XU && XU<=s.yu) return true;
    double YL=given_y(a,b,s.yl);
    if(s.xl<=YL && YL<=s.xu) return true;
    double YU=given_y(a,b,s.yu);
    if(s.xl<=YU && YU<=s.xu) return true;
    return false;
}

int square::judge(const rectangle &c) const{
    rep(i,4) if(this->inside(c.corners[i])) return 0;
    rep(i,4) if(cross((*this),c.corners[i],c.corners[(i+1)%4])) return 0;
    double big=OUT,small=OUT;
    rep(i,4) {
        auto tmp=given_x(c.corners[i], c.corners[(i+1)%4], xl);
        if(c.corners[i].x!=xl || c.corners[(i+1)%4].x!=xl) {
            if(tmp!=OUT){
                if(tmp>=yu) big=tmp;
                if(tmp<=yl) small=tmp;
            }
        }
    }
    /*this->print();
    c.print();
    cout<<big<<' '<<small<<endl;*/
    if(big==OUT) return -1;
    if(small==OUT) return -1;
    return 1;
}


double smallest=(1e-8);

struct one_question{
    ll N,R,C; 
    vector<rectangle> rec;
    vector<circle> cir;
    
    one_question(ll N_) :N(N_){
        rep(i,N){
            double a,b,c,d,r; cin>>a>>b>>c>>d>>r;
            Vec2 A(a,b), B(c,d);
            cir.pb(circle(A,r));
            if(A!=B){
                cir.pb(circle(B,r));
                rec.pb(rectangle(A,B,r));
            }
        }
        R=rec.size(); C=cir.size();
    }
    double Solve(const square& s, vec rec_memo, vec cir_memo){
        double full=s.len*s.len;
        if(full<=smallest) return full/2;
        bool nothing=true;
        rep(i,R) if(!rec_memo[i]){
            rec_memo[i]=s.judge(rec[i]);
            if(rec_memo[i]==1) return full;
            if(rec_memo[i]==0) nothing=false;
        }
        rep(i,C) if(!cir_memo[i]){
            cir_memo[i]=s.judge(cir[i]);
            if(cir_memo[i]==1) return full;
            if(cir_memo[i]==0) nothing=false;
        }
        if(nothing) return 0;
        double ret=0;
        rep(i,4){
            square tmp((s.mid+s.corners[i])/2,s.len/2);
            ret+=Solve(tmp,rec_memo,cir_memo);
        }
        return ret;

    }
    double ans(){
        square start(Vec2(0,0),10);
        vec rec_memo(R,0);
        vec cir_memo(C,0);
        return Solve(start,rec_memo,cir_memo);
    }

};




     

int main(){
    vector<double> ret;
    while(true){
        ll n; cin>>n;
        if(!n) break;
        one_question tmp(n);
        ret.pb(tmp.ans());
    }
    for(auto e: ret) cout<<setprecision(8)<<e<<endl;
}
accuracy: 1
time_ms: 1870
memory_kb: 3504
final_rank: 4

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

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

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}
P projection(const L& l, const P& p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}

bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}

P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}

VP crosspointCL(const C &c, const L &l){
    VP ret;
    P mid = projection(l, c.p);
    double d = distanceLP(l, c.p);
    if(EQ(d, c.r)){
        ret.push_back(mid);
    }else if(d < c.r){
        double len = sqrt(c.r*c.r -d*d);
        ret.push_back(mid +len*unit(l[1]-l[0]));
        ret.push_back(mid -len*unit(l[1]-l[0]));
    }
    return ret;
}
VP crosspointCS(const C &c, const L &s){
    VP ret;
    VP cp = crosspointCL(c,s);
    for(int i=0; i<(int)cp.size(); i++){
        if(intersectSP(s, cp[i])){
            ret.push_back(cp[i]);
        }
    }
    return ret;
}

int in_poly(const P &p, const VP &poly){
    int n = poly.size();
    int ret = -1;
    for(int i=0; i<n; i++){
        P a = poly[i]-p;
        P b = poly[(i+1)%n]-p;
        if(a.Y > b.Y) swap(a,b);
        if(intersectSP(L(a,b), P(0,0))) return 0;
        if(a.Y<=0 && b.Y>0 && cross(a,b)<0) ret = -ret;
    }
    return ret;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        vector<VP> rect(n, VP(4));
        vector<C> circle(2*n);
        for(int i=0; i<n; i++){
            double xs,ys,xt,yt,r;
            cin >> xs >> ys >> xt >> yt >> r;
            P s(xs, ys), t(xt, yt);
            P cn = unit(t -s) *r *P(0, 1);
            rect[i][0] = t +cn;
            rect[i][1] = s +cn;
            rect[i][2] = s -cn;
            rect[i][3] = t -cn;
            circle[2*i +0] = C(s, r);
            circle[2*i +1] = C(t, r);
        }

        double lbx=-5, ubx=5;
        double lby=-5, uby=5;
        int splitnum = 1e3;
        double dx = (ubx -lbx) /splitnum;
        double ans = 0;
        for(int i=0; i<splitnum; i++){
            double x = lbx +(i+0.5)*dx;
            L seg(P(x, lby), P(x, uby));
            VP cp{seg[0], seg[1]};
            for(int j=0; j<n; j++){
                for(int k=0; k<4; k++){
                    L edge(rect[j][k], rect[j][(k+1)%4]);
                    if(!isParallel(seg, edge) && intersectSS(seg, edge)){
                        cp.push_back(crosspointLL(seg, edge));
                    }
                }
            }
            for(int j=0; j<2*n; j++){
                VP ret = crosspointCS(circle[j], seg);
                cp.insert(cp.end(), ret.begin(), ret.end());
            }
            sort(cp.begin(), cp.end());
            cp.erase(unique(cp.begin(), cp.end()), cp.end());
            double len = 0;
            for(int j=0; j<(int)cp.size()-1; j++){
                P mid = (cp[j] +cp[j+1]) /2.0;
                bool in = false;
                for(int k=0; k<n && !in; k++){
                    if(in_poly(mid, rect[k]) > 0){
                        in = true;
                    }
                }
                for(int k=0; k<2*n && !in; k++){
                    if(abs(mid -circle[k].p) < circle[k].r){
                        in = true;
                    }
                }
                if(in){
                    len += abs(cp[j+1] -cp[j]);
                }
            }
            ans += dx*len;
        }
        cout << fixed << setprecision(5);
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3252
final_rank: 2

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

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

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}
P projection(const L& l, const P& p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}

bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}

P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}

VP crosspointCL(const C &c, const L &l){
    VP ret;
    P mid = projection(l, c.p);
    double d = distanceLP(l, c.p);
    if(EQ(d, c.r)){
        ret.push_back(mid);
    }else if(d < c.r){
        double len = sqrt(c.r*c.r -d*d);
        ret.push_back(mid +len*unit(l[1]-l[0]));
        ret.push_back(mid -len*unit(l[1]-l[0]));
    }
    return ret;
}
VP crosspointCS(const C &c, const L &s){
    VP ret;
    VP cp = crosspointCL(c,s);
    for(int i=0; i<(int)cp.size(); i++){
        if(intersectSP(s, cp[i])){
            ret.push_back(cp[i]);
        }
    }
    return ret;
}

int in_poly(const P &p, const VP &poly){
    int n = poly.size();
    int ret = -1;
    for(int i=0; i<n; i++){
        P a = poly[i]-p;
        P b = poly[(i+1)%n]-p;
        if(a.Y > b.Y) swap(a,b);
        if(intersectSP(L(a,b), P(0,0))) return 0;
        if(a.Y<=0 && b.Y>0 && cross(a,b)<0) ret = -ret;
    }
    return ret;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        vector<VP> rect(n, VP(4));
        vector<C> circle(2*n);
        for(int i=0; i<n; i++){
            double xs,ys,xt,yt,r;
            cin >> xs >> ys >> xt >> yt >> r;
            P s(xs, ys), t(xt, yt);
            P cn = unit(t -s) *r *P(0, 1);
            rect[i][0] = t +cn;
            rect[i][1] = s +cn;
            rect[i][2] = s -cn;
            rect[i][3] = t -cn;
            circle[2*i +0] = C(s, r);
            circle[2*i +1] = C(t, r);
        }

        double lbx=-5, ubx=5;
        double lby=-5, uby=5;
        int splitnum = 1e4;
        double dx = (ubx -lbx) /splitnum;
        double ans = 0;
        for(int i=0; i<splitnum; i++){
            double x = lbx +(i+0.5)*dx;
            L seg(P(x, lby), P(x, uby));
            VP cp{seg[0], seg[1]};
            for(int j=0; j<n; j++){
                for(int k=0; k<4; k++){
                    L edge(rect[j][k], rect[j][(k+1)%4]);
                    if(!isParallel(seg, edge) && intersectSS(seg, edge)){
                        cp.push_back(crosspointLL(seg, edge));
                    }
                }
            }
            for(int j=0; j<2*n; j++){
                VP ret = crosspointCS(circle[j], seg);
                cp.insert(cp.end(), ret.begin(), ret.end());
            }
            sort(cp.begin(), cp.end());
            cp.erase(unique(cp.begin(), cp.end()), cp.end());
            double len = 0;
            for(int j=0; j<(int)cp.size()-1; j++){
                P mid = (cp[j] +cp[j+1]) /2.0;
                bool in = false;
                for(int k=0; k<n && !in; k++){
                    if(in_poly(mid, rect[k]) > 0){
                        in = true;
                    }
                }
                for(int k=0; k<2*n && !in; k++){
                    if(abs(mid -circle[k].p) < circle[k].r){
                        in = true;
                    }
                }
                if(in){
                    len += abs(cp[j+1] -cp[j]);
                }
            }
            ans += dx*len;
        }
        cout << fixed << setprecision(5);
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 920
memory_kb: 3312
final_rank: 3

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define REP(i, s, e) for ( int i = s; i <= e; i++ )  
 
const double INF = 1e12;
typedef complex<double> P,point;
 
std::istream& operator>>(std::istream& is,P& p)
{
	is >> p.real() >> p.imag();
	return is;
}
 
typedef vector<P> G,polygon;
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(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);}
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);} };
struct C {P p; double r;C(const P &p, double r) : p(p), r(r) { } C(){} };
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;
}
 
// Check Funcs //
bool intersectLL(const L &l, const L &m) {return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;}
bool intersectLS(const L &l, const L &s) {return cross(l[1]-l[0], s[0]-l[0])*cross(l[1]-l[0], s[1]-l[0]) < EPS;}
bool intersectLP(const L &l, const P &p) {return abs(cross(l[1]-p, l[0]-p)) < EPS;}
bool intersectSS(const L &s, const L &t) {return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;}
bool intersectSP(const L &s, const P &p) {return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS;}
 
// Where is Point in Polygon? //
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
enum { OUT, ON, IN };
int contains(const polygon& P, const point& p) {
	bool in = false;
	for (int i = 0; i < P.size(); ++i) {
		point a = curr(P,i) - p, b = next(P,i) - p;
		if (imag(a) > imag(b)) swap(a, b);
		if (imag(a) <= 0 && 0 < imag(b))
			if (cross(a, b) < 0) in = !in;
		if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
	}
	return in ? IN : OUT;
}
// Area of Polygon //
double area2(const polygon& P) {
	double A = 0;
	for (int i = 0; i < P.size(); ++i)A += cross(curr(P, i), next(P, i));
	return A;
}
// Totsuhou! Andrew's Monotone Chain //
 
vector<point> convex_hull(vector<point> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<point> ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}
 
P projection(const L &l, const P &p) {double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);return l[0] + t*(l[0]-l[1]);}
P reflection(const L &l, const P &p) {return p + 2.0 * (projection(l, p) - p);}
 
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
	return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
	if (intersectLS(l, s)) return 0;
	return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
	const P r = projection(s, p);
	if (intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
	if (intersectSS(s, t)) return 0;
	return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
 
P crosspoint(const L &l, const L &m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (abs(A) < EPS && abs(B) < EPS) return m[0];
	return m[0] + B / A * (m[1] - m[0]);
}
 
vector<P> C_cp(C a,C b){
	vector<P> ret;
	double L = abs(a.p-b.p);
 
	/* anma dekitenai */
	if(	L-a.r-b.r > EPS || (abs(a.p-b.p)<EPS && fabs(a.r-b.r)<EPS) || 
		abs(a.p-b.p) < abs(a.r-b.r)
	)return ret;
 
	double theta = atan2(b.p.imag()-a.p.imag(),b.p.real()-a.p.real());
	double c = (L*L+a.r*a.r-b.r*b.r)/(2*L*a.r);
	ret.push_back(
		P(a.p.real()+a.r*cos(theta+acos(c)),
		  a.p.imag()+a.r*sin(theta+acos(c)))
	);
	if(fabs(L-a.r-b.r) > EPS)
		ret.push_back(
			P(a.p.real()+a.r*cos(theta-acos(c)),
			  a.p.imag()+a.r*sin(theta-acos(c)))
		);
	return ret;
}
 
 
P getPedal(L l, P p){
	double A;
	if(abs(l[1].real()-l[0].real()) < EPS){
		return P(l[1].real(),p.imag()); // important
	}else{
		A = (l[1].imag()-l[0].imag())/(l[1].real()-l[0].real());
	}
	double a = -A , b = 1 , c = A*l[0].real() - l[0].imag();
	double t = (a*p.real() + b*p.imag() + c)/(a*a+b*b);
	return p-t * P(a,b);
}
 
vector<P> crosspointCL(const L l, const C c){
	vector<P> ret;
	P p = getPedal(l,c.p);
	if(	abs(p-c.p) > c.r+EPS)return ret;
	P e = P((l[1]-l[0])/abs(l[1]-l[0]));
	double S = sqrt(c.r*c.r-abs(p-c.p)*abs(p-c.p));
	ret.push_back(p+S*e);
	ret.push_back(p-S*e);
	return ret;
}
 
P getCircumcenter(P a,P b,P c){
	double A1 = 2 * ( b.real() - a.real() );
	double B1 = 2 * ( b.imag() - a.imag() );
	double C1 = pow(a.real(),2)-pow(b.real(),2) + pow(a.imag(),2)-pow(b.imag(),2);
	double A2 = 2 * ( c.real() - a.real() );
	double B2 = 2 * ( c.imag() - a.imag() );
	double C2 = pow(a.real(),2)-pow(c.real(),2) + pow(a.imag(),2)-pow(c.imag(),2);
	double X = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
	double Y = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
	return P(X,Y);
}
 
double AreaOfPolygon(vector<P> p){
	double S = 0 ; 
	p.push_back(p[0]);
	/*　多角形の面積公式 (反時計回りの場合) */
	for(int i = 0 ; i < p.size()-1 ; i++){
		S += (p[i].real() - p[i+1].real()) * (p[i].imag()+p[i+1].imag());
	}
	S /= 2.0;
	return S;
}
vector<vector<L> > rect;

vector<C> c;
double seg(double y){
	L l = L(P(0,y),P(1,y));
	vector< pair<double,double> > segs;
	for(int i = 0 ; i < c.size() ; i++){
		vector<P> cp = crosspointCL(l,c[i]);
		if( cp.size() ){
			double a = cp[0].real(), b = cp[1].real();
			if( a > b ) swap(a,b);
			segs.push_back(mp(a,b));
		}
	}
	for(int i = 0 ; i < rect.size() ; i++){
		double mx = -1e9;
		double mi = 1e9;
		for(int j = 0 ; j < 4 ; j++){
			if( intersectLS(l,rect[i][j]) ){
				double x = crosspoint(rect[i][j],l).real();
				mx = max(mx,x);
				mi = min(mi,x);
			}
		}
		if( mi > mx ) continue;
		//cout << mi << " " << mx << endl;
		segs.push_back(mp(mi,mx));
	}
	vector< pair<double,double> > tmpseg;
	for(int i = 0 ; i < segs.size() ; i++){
		if( segs[i].second < -5 ) continue;
		if( segs[i].first > 5 ) continue;
		segs[i].first = max(-5.,segs[i].first);
		segs[i].second = min(5.,segs[i].second);
		tmpseg.push_back(segs[i]);
	}
	segs = tmpseg;
	
	if( segs.size() == 0 ) return 0.0;
	sort(segs.begin(),segs.end());
	double st = segs[0].first;
	double en = segs[0].second;
	double ans = 0;
	for(int i = 1 ; i < segs.size() ; i++){

		if( en < segs[i].first ){
			ans += en - st;
			st = segs[i].first;
			en = segs[i].second;
		}else{
			en = max(en,segs[i].second);
		}
	}
	ans += en - st;
	return ans;
}
int main(){
	int N;
	while(cin >> N && N){
		c.clear();
		rect.clear();
		for(int i = 0 ; i < N ; i++){
			P a,b;
			double r;
			cin >> a >> b >> r;
			P e = (b - a) / abs(b-a);
			e = P(-e.imag(),e.real());
			vector<L> ln;
			P A = a + e * r;
			P B = a - e * r;
			P C = b - e * r;
			P D = b + e * r;
			ln.push_back(L(A,B));
			ln.push_back(L(B,C));
			ln.push_back(L(C,D));
			ln.push_back(L(D,A));
			
			rect.push_back(ln);
			c.push_back(::C(a,r));
			c.push_back(::C(b,r));
		}
		double ans = 0;
		int D = 20000;
		//cout << seg(1.3) << endl;
		//return 0;
		for(int i = 0 ; i < D ; i++){
			double y = -5 + 10. * i / D;
			ans += seg(y) * (1./D);
		}
		printf("%.10lf%c",ans*10,10);
	}
}
accuracy: 1
time_ms: 960
memory_kb: 1312
final_rank: 1