# poj 3335 Rotating Scoreboard （半平面交）

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（半平面交）

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4370   Accept...
• u010527492
• 2013年08月20日 10:28
• 587

## POJ 3335: Rotating Scoreboard 半平面交

Rotating ScoreboardTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 7505 Accepted: 3008Desc...
• BlackJack_
• 2018年02月12日 22:30
• 47

## Rotating Scoreboard - POJ 3335 半平面交

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 570...
• u014733623
• 2015年05月08日 14:59
• 241

## POJ 3335 Rotating Scoreboard (半平面交)

• u013112097
• 2014年06月23日 18:08
• 220

## POJ 3335 Rotating Scoreboard 半平面交

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

## poj 3335 Rotating Scoreboard(半平面交)

• gyhguoge01234
• 2017年04月18日 20:53
• 163

## poj 3335 Rotating Scoreboard - 半平面交

/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include #include const double eps=1e-8; cons...
• qq172108805
• 2013年08月08日 10:50
• 701

## poj 3335 Rotating Scoreboard

• lj94093
• 2014年12月08日 23:46
• 289

## Rotating Scoreboard POJ - 3335

This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and...
• yyxiangyu
• 2017年09月27日 19:57
• 65

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

• FXXKI
• 2015年05月09日 20:30
• 417

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