# poj 1279 Art Gallery （半平面交）

Art Gallery
 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7280 Accepted: 2923

Description

The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form of polygons (not necessarily convex). When a big exhibition is organized, watching over all of the pictures is a big security concern. Your task is that for a given gallery to write a program which finds the surface of the area of the floor, from which each point on the walls of the gallery is visible. On the figure 1. a map of a gallery is given in some co-ordinate system. The area wanted is shaded on the figure 2.

Input

The number of tasks T that your program have to solve will be on the first row of the input file. Input data for each task start with an integer N, 5 <= N <= 1500. Each of the next N rows of the input will contain the co-ordinates of a vertex of the polygon ? two integers that fit in 16-bit integer type, separated by a single space. Following the row with the co-ordinates of the last vertex for the task comes the line with the number of vertices for the next test and so on.

Output

For each test you must write on one line the required surface - a number with exactly two digits after the decimal point (the number should be rounded to the second digit after the decimal point).

Sample Input

1
7
0 0
4 4
4 7
9 7
13 -1
8 -6
4 -4

Sample Output

80.00

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define  N 2000
#define eps 1e-8
#define inf 1e9
using namespace std;
struct vector {
double x,y;
vector (double X=0,double Y=0){
x=X,y=Y;
}
}a[N],p[N],tmp[N];
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 t){
return vector (a.x*t,a.y*t);
}
int n,m;
double cross(vector a,vector b)
{
return a.x*b.y-a.y*b.x;
}
point glt(point a,point a1,point b,point b1)
{
vector v=a1-a; vector w=b1-b;
vector u=a-b;
double t=cross(w,u)/cross(v,w);
return a+v*t;
}
void init()
{
m=0;
p[m++]=point(inf,inf);
p[m++]=point(-inf,inf);
p[m++]=point(-inf,-inf);
p[m++]=point(inf,-inf);
}
void cut(point a,point b)
{
int cnt=0;
memset(tmp,0,sizeof(tmp));
for (int i=0;i<m;i++){
double c=cross(b-a,p[i]-a);
double d=cross(b-a,p[(i+1)%m]-a);
if (c>=0) tmp[cnt++]=p[i];
if (c*d<0)
tmp[cnt++]=glt(a,b,p[i],p[(i+1)%m]);
}
m=cnt;
for (int i=0;i<cnt;i++) p[i]=tmp[i];
}
int main()
{
freopen("a.in","r",stdin);
int T;
scanf("%d",&T);
while (T--) {
scanf("%d",&n);
if (!n) break;
for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
a[n+1]=a[1];
init();
for (int i=2;i<=n+1;i++){
cut(a[i],a[i-1]);
if (!m) break;
}
double area=0;
p[m]=p[0];
for (int i=1;i<m;i++)
area+=cross(p[i]-p[0],p[i+1]-p[0]);
printf("%.2lf\n",fabs(area)/2);
}
}

• 本文已收录于以下专栏：

## POJ 1279 || Art Gallery(半平面交求核面积

• FXXKI
• 2015年05月12日 20:00
• 469

## POJ 1279 Art Gallery （半平面交求内核面积）

Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7508   Accepted: 2996...

## poj1279-Art Gallery 直线围成的区域的面积（半平面交模板题）

Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7997   Accepted: 3182...

## POJ 1279 Art Gallery （多边形组成的内核面积）

【题目链接】：click here~~ 【题目大意】求多边形组成的内核面积 【思路】：模板题参考上一题 代码： /* * Problem: POJ No.1279 * Running time: 16...

## POJ 1279 Art Gallery

POJ 1279 Art Gallery 半平面交的直接应用。 #include #include #include #include #include #include #include...
• utoppia
• 2013年08月22日 19:12
• 422

## poj-1279 Art Gallery

举报原因： 您举报文章：poj 1279 Art Gallery （半平面交） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)