poj 1279 Art Gallery (半平面交)

原创 2017年01月03日 09:55:45

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(半平面交求核面积

注意下一输入的点是逆时针或者顺时针,用面积判定一下是正负就可以啦,统一调整一下 然后算出半平面交核的点集,求面积一下就OK了~ #include #include #include #includ...
  • FXXKI
  • FXXKI
  • 2015年05月12日 20:00
  • 469

POJ 1279 Art Gallery 半平面交求面积

和CQOI 2006 凸多边形就多组数据的区别。。 #include #include #include using namespace std; const int N = 1502; st...

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(半平面交求多边形核)

转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:求多边形核的面积。 ...

poj1279——Art Gallery//半平面交 求面积

用上题模板,一次AC。#include #include #include using namespace std; const int maxn=20010; const int boun...

POJ1279/ZOJ1369 Art Gallery,POJ2451 Uyuw's Concert(半平面交求多边形的核)

传说中的半平面交…… 看的是朱泽园 06 年的论文,他自创的排序增量法,n*logn 的复杂度,相当给力 PS:朱泽园为了他的论文,专门在POJ上加了一道题,就是 POJ2451 Uyuw's C...

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
  • utoppia
  • 2013年08月22日 19:12
  • 422

poj-1279 Art Gallery

题意: 给出一个n个点的多边形,求多边形核的面积; 多边形的核即为多边形内部的点集,使其中的点可以看到多边形的任意顶点和边; n 题解: 这应该也算是模板题的一种吧; 求多边形核的方法现在是O(...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 1279 Art Gallery (半平面交)
举报原因:
原因补充:

(最多只允许输入30个字)