#include <bits/stdc++.h>
using namespace std;
const int maxn = 35;
int n;
double a[maxn], b[maxn], c[maxn], d[maxn];
struct Point
{
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;
typedef vector<Point> Polygon;
Vector operator +(Vector A, Vector B)//
{
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator -(Point A, Point B)//
{
return Vector(A.x - B.x , A.y - B.y);
}
Vector operator *(Vector A, double p)//
{
return Vector(A.x * p, A.y * p);
}
Vector operator /(Vector A, double p)//
{
return Vector(A.x / p, A.y / p);
}
bool operator <(const Point &a, const Point &b)//
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
const double eps = 1e-10;
int dcmp(double x)//
{
if (fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
bool operator ==(const Point &a, const Point &b)//
{
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector A, Vector B)//
{
return A.x * B.x + A.y * B.y;
}
double Length(Vector A)//
{
return sqrt(Dot(A, A));
}
double Angle(Vector A, Vector B)//
{
return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Vector A, Vector B)//
{
return A.x * B.y - A.y * B.x;
}
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) //
{
Vector u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
bool OnSegment(Point p, Point a1, Point a2) //
{
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
double PolygonArea(Polygon &p) //
{
double area = 0;
for (int i = 1; i < p.size() - 1; i++)
area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
Polygon CutPolygon(Polygon poly, Point A, Point B)
{
Polygon newpoly;
int n = poly.size();
for (int i = 0; i < n; i++)
{
Point C = poly[i];
Point D = poly[(i + 1) % n];
if (dcmp(Cross(B - A, C - A)) >= 0) newpoly.push_back(C);
if (dcmp(Cross(B - A, C - D)) != 0)
{
Point ip = GetLineIntersection(A, B - A, C, D - C);
if (OnSegment(ip, C, D)) newpoly.push_back(ip);
}
}
return newpoly;
}
vector<Polygon>pieces;
int main(int argc, char const *argv[])
{
while (~scanf("%d", &n) && n)
{
pieces.clear();
Polygon poly;
poly.push_back(Point(0, 0));
poly.push_back(Point(1, 0));
poly.push_back(Point(1, 1));
poly.push_back(Point(0, 1));
pieces.push_back(poly);
for (int i = 0; i < n; i++)
scanf("%lf", &a[i]);
for (int i = 0; i < n; i++)
scanf("%lf", &b[i]);
for (int i = 0; i < n; i++)
scanf("%lf", &c[i]);
for (int i = 0; i < n; i++)
scanf("%lf", &d[i]);
for (int i = 0; i < n; i++)
{
vector<Polygon> temp1, temp2;
for (int j = 0; j < pieces.size(); j++)
{
Polygon poly1 = CutPolygon(pieces[j], Point(a[i], 0), Point(b[i], 1));
Polygon poly2 = CutPolygon(pieces[j], Point(b[i], 1), Point(a[i], 0));
if (poly1.size() >= 3)
temp1.push_back(poly1);
if (poly2.size() >= 3)
temp1.push_back(poly2);
}
pieces = temp1;
for (int j = 0; j < pieces.size(); j++)
{
Polygon poly3 = CutPolygon(pieces[j], Point(0, c[i]), Point(1, d[i]));
Polygon poly4 = CutPolygon(pieces[j], Point(1, d[i]), Point(0, c[i]));
if (poly3.size() >= 3)
temp2.push_back(poly3);
if (poly4.size() >= 3)
temp2.push_back(poly4);
}
pieces = temp2;
}
double maxx = -1;
for (int i = 0; i < pieces.size(); i++)
maxx = max(maxx, PolygonArea(pieces[i]));
printf("%lf\n", maxx);
}
return 0;
}
熟练运用书上模板,暴力切割就可以了。