# poj 3335 Rotating Scoreboard （半平面交）

224人阅读 评论(0)

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");
}
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：266011次
• 积分：14910
• 等级：
• 排名：第795名
• 原创：1282篇
• 转载：12篇
• 译文：0篇
• 评论：70条
欢迎交流
QQ：1184204539
友链~\(≧▽≦)/~啦啦啦
阅读排行
最新评论