测测自己改的新板子,挺对的
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#define maxl 20010
#define eps 1e-8
using namespace std;
inline int sgn(double x)
{
if(x>-eps && x<eps) return 0;
if(x>0) return 1;
else return -1;
}
struct point
{
double x,y;
point(double a=0,double b=0)
{
x=a,y=b;
}
point operator + (const point &b)const
{
return point(x+b.x,y+b.y);
}
point operator - (const point &b)const
{
return point(x-b.x,y-b.y);
}
friend point operator * (const double &t,const point &a)
{
return point(t*a.x,t*a.y);
}
inline bool operator == (const point &b)const
{
return sgn(x-b.x)==0 && sgn(y-b.y)==0;
}
inline double norm()
{
return sqrt(x*x+y*y);
}
};
inline double dot(const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
}
inline double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
struct halfplane
{// s->e on the left
point s,e;
double k;
halfplane(point a=point(),point b=point())
{
s=a;e=b;
k=atan2(e.y-s.y,e.x-s.x);
}
point operator &(const halfplane &b)const
{
double t=det(b.s-s,b.e-b.s);
t=t/det(e-s,b.e-b.s);
return s+t*(e-s);
}
};
inline bool satisfy(point a,const halfplane L)
{//不允许在线上
return sgn(det(a-L.s,L.e-L.s))<=0;
}
inline bool HPIcmp(const halfplane &a,const halfplane &b)
{//如果平行且同向,内侧的在前
int res=sgn(a.k-b.k);
return res==0 ? det(a.s-b.s,b.e-b.s)<0 : a.k<b.k;
}
halfplane Q[maxl];
void HPI(halfplane line[],int n,point res[],int &resn)
{
int tot=n;
sort(line,line+n,HPIcmp);
tot=1;
for(int i=1;i<n;i++)
if(sgn(line[i].k-line[i-1].k)!=0)
line[tot++]=line[i];
int head=0,tail=1;
Q[0]=line[0];
Q[1]=line[1];
resn=0;
for(int i=2;i<tot;i++)
{
if(sgn(det(Q[tail].e-Q[tail].s,Q[tail-1].e-Q[tail-1].s))==0||
sgn(det(Q[head].e-Q[head].s,Q[head+1].e-Q[head+1].s))==0)
return;
while(head<tail && !satisfy(Q[tail]&Q[tail-1],line[i]))
tail--;
while(head<tail && !satisfy(Q[head]&Q[head+1],line[i]))
head++;
Q[++tail]=line[i];
}
while(head<tail && !satisfy(Q[tail]&Q[tail-1],Q[head]))
tail--;
while(head<tail && !satisfy(Q[head]&Q[head+1],Q[tail]))
head++;
if(tail<=head+1) return;
for(int i=head;i<tail;i++)
res[resn++]=Q[i]&Q[i+1];
if(head<tail-1)
res[resn++]=Q[head]&Q[tail];
}
int n,resn;
halfplane a[maxl];
point res[maxl];
double ans;
const double inf=10000;
inline void prework()
{
point s,e;
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf",&s.x,&s.y,&e.x,&e.y);
a[i]=halfplane(s,e);
}
a[n++]=(halfplane(point(0,0),point(inf,0)));
a[n++]=(halfplane(point(inf,0),point(inf,inf)));
a[n++]=(halfplane(point(inf,inf),point(0,inf)));
a[n++]=(halfplane(point(0,inf),point(0,0)));
}
inline double area(point a[],int n)
{
double sum=0;
if(n<3)
return 0;
for(int i=0;i<n;i++)
sum+=det(a[(i+1)%n],a[i]);
return fabs(sum/2);
}
inline void mainwork()
{
HPI(a,n,res,resn);
ans=area(res,resn);
}
inline void print()
{
printf("%.1f\n",ans);
}
int main()
{
while(~scanf("%d",&n))
{
prework();
mainwork();
print();
}
return 0;
}