poj 3335 Rotating Scoreboard (半平面交)

原创 2017年01月03日 08:37:07

Rotating Scoreboard
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6815   Accepted: 2706

Description

This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the edges of the polygon. We want to place a rotating scoreboard somewhere in the hall such that a spectator sitting anywhere on the boundary of the hall can view the scoreboard (i.e., his line of sight is not blocked by a wall). Note that if the line of sight of a spectator is tangent to the polygon boundary (either in a vertex or in an edge), he can still view the scoreboard. You may view spectator's seats as points along the boundary of the simple polygon, and consider the scoreboard as a point as well. Your program is given the corners of the hall (the vertices of the polygon), and must check if there is a location for the scoreboard (a point inside the polygon) such that the scoreboard can be viewed from any point on the edges of the polygon.

Input

The first number in the input line, T is the number of test cases. Each test case is specified on a single line of input in the form n x1 y1 x2 y2 ... xn yn where n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integers xi yi sequence specify the vertices of the polygon sorted in order.

Output

The output contains T lines, each corresponding to an input test case in that order. The output line contains either YES or NO depending on whether the scoreboard can be placed inside the hall conforming to the problem conditions.

Sample Input

2
4 0 0 0 1 1 1 1 0
8 0 0  0 2  1 2  1 1  2 1  2 2  3 2  3 0

Sample Output

YES
NO

Source

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


题目大意:求多边形是否有内核。

题解:半平面交

什么是多边形的内核?

它是平面简单多边形的核是该多边形内部的一个点集,该点集中任意一点与多边形边界上一点的连线都处于这个多边形内部。就是一个在一个房子里面放一个摄像 头,能将所有的地方监视到的放摄像头的地点的集合即为多边形的核。

 

         

如上图,第一个图是有内核的,比如那个黑点,而第二个图就不存在内核了,无论点在哪里,总有地区是看不到的。

那么我们可以用半平面交来解决这个问题,用多边形相邻两个顶点确定的直线切割平面,每次取直线的一侧,同左或同右。

这道题卡精度,叉积求交点的方法过不了。。。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define N 203
#define eps 1e-8
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];
int n,m;
double inf=1e18;
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);}
Vector operator /(Vector a,double t) {
	return Vector (a.x/t,a.y/t);
}
bool operator ==(Vector a,Vector b){return a.x==b.x&&a.y==b.y;}
bool operator !=(Vector a,Vector b) {
	return a.x!=b.x||a.y!=b.y;
}
int dcmp(double x)
{
	if (fabs(x)<eps) return 0;
	return x<0?-1:1;
}
double cross(Vector a,Vector b)
{
	return a.x*b.y-a.y*b.x;
}
point line_intersection(point a,point a0,point b,point b0)
{
    double a1,b1,c1,a2,b2,c2;
    a1 = a.y - a0.y;
    b1 = a0.x - a.x;
    c1 = cross(a,a0);
    a2 = b.y - b0.y;
    b2 = b0.x - b.x;
    c2 = cross(b,b0);
    double d = a1 * b2 - a2 * b1;
    return point((b1 * c2 - b2 * c1) / d,(c1 * a2 - c2 * a1) / d);
} 
double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
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 dn=0;
	double t1,t2;
	for (int i=0;i<m;i++){
		t1=cross((b-a),(p[i]-a));
		t2=cross((b-a),(p[(i+1)%m]-a));
		if (dcmp(t1)>=0) tmp[dn++]=p[i];
		if (dcmp(t1)*dcmp(t2)<0) 
		 tmp[dn++]=line_intersection(a,b,p[i],p[(i+1)%m]);
	}
	m=0;
	for (int i=0;i<dn;i++)
	  p[m++]=tmp[i];
}
int main()
{
	freopen("a.in","r",stdin);
	int T;
	scanf("%d",&T);
	while (T--){
		scanf("%d",&n);
		memset(a,0,sizeof(a));
		for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
		init();
		a[n+1]=a[1];
		for (int i=2;i<=n+1;i++){
		 cut(a[i],a[i-1]);
		 if (!m) break;
	    }
		if (m) printf("YES\n");
		else printf("NO\n");
	}
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

POJ 3335 Rotating Scoreboard

题目大意:同   POJ3130 解题思路:同   POJ3130 POJ3130解题报告:点此进入 注意:两个题给出点的顺序不一样。不要老是抄模版(我不会告诉你我就是这么做的)...

poj3130 && poj3335 半平面交

这两个题,都是输入一个简单多边形,判断是否存在核,套半平面交模版即可。 贴代码: //poj3130 #include #include #include #include using n...

POJ 3335 Rotating Scoreboard 半平面交

POJ 3335 Rotating Scoreboard 半平面交
  • wzq_QwQ
  • wzq_QwQ
  • 2015年09月16日 16:52
  • 708

poj 3335 Rotating Scoreboard

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissi...
  • wwwzys
  • wwwzys
  • 2011年09月05日 11:00
  • 1566

poj3335 Rotating Scoreboard【半平面交】

题目链接:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的,问你是否在球场上有个地方可以放一个记分牌,然后所有的...

poj3335-Rotating Scoreboard 判断多边形是否有内核(模板题)

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7108   Accept...

Poj 3335 Rotating Scoreboard (多边形求核)

题目链接:http://poj.org/problem?id=3335 题目中点的顺序均为顺时针。 第一道多边形求交的题,有别人的代码做参考还写的各种水……最惨的是WA的原因居然是调试用的代码没有...

POJ 3335||Rotating Scoreboard(半平面交求核

新抄一个模板,再学习。 #include #include #include #include #define eps 1e-8 using namespace std; const in...
  • FXXKI
  • FXXKI
  • 2015年05月09日 20:30
  • 376

poj 3335 Rotating Scoreboard(半平面交)

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4370   Accept...

POJ 3335-Rotating Scoreboard(计算几何-半平面交顺时针模板)

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6963   Accept...
  • MIKASA3
  • MIKASA3
  • 2017年04月16日 20:37
  • 232
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 3335 Rotating Scoreboard (半平面交)
举报原因:
原因补充:

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