"No regrets."

## 代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 10005

const double inf=1e9;
const double eps=1e-9;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return 0;
return (x>0)?1:-1;
}
struct Vector
{
double x,y;
Vector(double X=0,double Y=0)
{
x=X,y=Y;
}
};
typedef Vector Point;
Vector operator + (Vector a,Vector b) {return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector 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);}

int T,n,cnt,ncnt;
double x,y,ans;
Point p[N],poly[N],npoly[N];

double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
bool insLS(Point A,Point B,Point C,Point D)
{
Vector v=B-A,w=C-A,u=D-A;
return dcmp(Cross(v,w))!=dcmp(Cross(v,u));
}
Point GLI(Point P,Vector v,Point Q,Vector w)
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}
void init()
{
cnt=0;
poly[++cnt]=Point(inf,inf);
poly[++cnt]=Point(inf,-inf);
poly[++cnt]=Point(-inf,-inf);
poly[++cnt]=Point(-inf,inf);
}
void halfp(Point A,Point B)
{
ncnt=0;
Point C,D;
for (int i=1;i<=cnt;++i)
{
C=poly[i%cnt+1];
D=poly[(i+1)%cnt+1];
if (dcmp(Cross(B-A,C-A))<=0)
npoly[++ncnt]=C;
if (insLS(A,B,C,D))
npoly[++ncnt]=GLI(A,B-A,C,D-C);
}
cnt=ncnt;
for (int i=1;i<=cnt;++i)
poly[i]=npoly[i];
}
double Area()
{
double area=0;
for (int i=2;i<cnt;++i)
area+=Cross(poly[i]-poly[1],poly[i+1]-poly[1]);
return fabs(area/2.0);
}
int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (int i=1;i<=n;++i)
{
scanf("%lf%lf",&x,&y);
p[i]=Point(x,y);
}
init();
for (int i=1;i<=n;++i)
halfp(p[i%n+1],p[(i+1)%n+1]);
ans=Area();
printf("%.2lf\n",ans);
}
}

#### POJ1279 Art Gallery

2017-02-16 10:31:47

#### poj1279Art Gallery【半平面交求内核面积】

2015-09-14 23:45:35

#### POJ 1279 Art Gallery（半平面交求多边形核）

2012-08-19 11:36:21

#### POJ1279Art Gallery

2017-08-21 15:02:22

#### poj-1279 Art Gallery

2015-09-07 13:35:33

#### POJ1279(求多边形内核的面积)

2013-04-12 19:30:38

#### poj 1279

2016-07-29 17:51:32

#### POJ 1279 Art Gallery 半平面交+求多边形核的面积

2015-04-09 21:32:53

#### POJ1279-Art Gallery

2014-07-26 19:57:17

#### 半平面交 poj1279 3335 3130

2013-10-26 18:48:29

## 不良信息举报

[POJ1279]Art Gallery（半平面交）