#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int read()
{
int out=0,sgn=1;
char jp=getchar();
while(jp!='-' && (jp<'0' || jp>'9'))
jp=getchar();
if(jp=='-')
sgn=-1,jp=getchar();
while(jp>='0' && jp<='9')
out=out*10+jp-'0',jp=getchar();
return out*sgn;
}
const int MAXN=1e5+10;
struct v2
{
double x,y;
v2(double x=0,double y=0):x(x),y(y) {}
friend double operator * (const v2 &a,const v2 &b)
{
return a.x*b.y-a.y*b.x;
}
v2 operator + (const v2 &rhs) const
{
return v2(x+rhs.x,y+rhs.y);
}
v2 operator - (const v2 &rhs) const
{
return v2(x-rhs.x,y-rhs.y);
}
v2 operator ^ (const double &lambda) const
{
return v2(x*lambda,y*lambda);
}
double modulus()
{
return sqrt(x*x+y*y);
}
double angle()
{
return atan2(y,x);
}
bool operator < (const v2 &rhs) const
{
return x==rhs.x?y<rhs.y:x<rhs.x;
}
};
struct Line
{
v2 p,v;
double angle()
{
return v.angle();
}
friend bool operator < (Line a,Line b)
{
if(a.angle()!=b.angle())
return a.angle()<b.angle();
return a.v*b.v<0;
}
};
bool Onleft(Line L,v2 p)
{
return (L.v*(p-L.p))>0;
}
v2 Intersection(Line a,Line b)
{
v2 u=a.p-b.p;
double t=(b.v*u)/(a.v*b.v);
return a.p+(a.v^t);
}
int head,tail,n;//n-the num of Lines
Line q[MAXN],L[MAXN];
v2 p[MAXN];
void Hpi()
{
sort(L+1,L+1+n);
q[head=tail=1]=L[1];
for(int i=2;i<=n;++i)
{
while(head<tail && !Onleft(L[i],p[tail-1]))
--tail;
while(head<tail && !Onleft(L[i],p[head]))
++head;
++tail;
q[tail]=L[i];
if(head<tail && (q[tail].v*q[tail-1].v)==0)
{
--tail;
if(Onleft(q[tail],L[i].p))
q[tail]=L[i];
}
if(head<tail)
p[tail-1]=Intersection(q[tail-1],q[tail]);
}
while(head<tail && !Onleft(q[head],p[tail-1]))
--tail;
p[tail]=Intersection(q[tail],q[head]);
p[tail+1]=p[head];
double area=0;
v2 O=v2(0,0);
for(int i=head;i<=tail;++i)
area+=((O-p[i])*(O-p[i+1]));
printf("%.2lf\n",fabs(area/2.0));
}
int main()
{
return 0;
}
转载于:https://www.cnblogs.com/jklover/p/11303018.html