Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9178 Accepted: 3606 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 0Sample Output
YES NO
题目大意:让你在大厅内设置一个播放器,现在给你这个播放器的顶点坐标,现在问你这个播放器能否让在场所有观众看到,
思路:半平面交模板题,注意输入的点是顺时针方向,而我们的线段要得是逆时针方向,最后看他的核是否存在即可
代码:
/*
题目大意:
思路:
*/
#include<set>
#include<map>
#include<ctime>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f
#define bug printf("bug\n")
const int maxn=1e6+10;
const double pi=acos(-1.0);
const double esp=1e-6;
const int N=2e2+10;
int sign(double x)
{
if(x==0)
return 0;
return x>0?1:-1;
}
struct point
{
double x,y;
point () {}
point(double _x,double _y)
{
x=_x;
y=_y;
}
point operator -(const point &b)const
{
return point (x-b.x,y-b.y);
}
double operator ^(const point &b)const
{
return x*b.y-b.x*y;
}
double operator *(const point &b)const
{
return x*b.x+y*b.y;
}
};
struct line
{
point st,ed;
double k,b;
line() {}
line(point _s,point _e)
{
st=_s,ed=_e;
k=atan2(ed.y-st.y,ed.x-st.x);
}
point operator &(const line &b)const///得到两个直线的交点
{
point res=st;
double t=((st-b.st)^(b.st-b.ed))/((st-ed)^(b.st-b.ed));
res.x+=(ed.x-st.x)*t;
res.y+=(ed.y-st.y)*t;
return res;
}
};
point p[maxn];
line l[1010];
bool cmp(line a,line b)
{
if(fabs(a.k-b.k)>esp)
return a.k<b.k;
return((a.st-b.st)^(b.ed-b.st))<0;
}
void hpi(line line[], int n, point res[], int &resn)
{
int tot=n;
sort(line,line+n,cmp);
tot=1;
for(int i=1; i<n; i++)
{
if(fabs(line[i].k-line[i-1].k)>esp)
line[tot++]=line[i];
}
int head=0, tail=1;
l[0] = line[0];
l[1] = line[1];
resn = 0;
for(int i=2; i<tot; i++)
{
if(fabs((l[tail].ed-l[tail].st)^(l[tail-1].ed-l[tail-1].st))<esp||fabs((l[head].ed-l[head].st)^(l[head+1].ed-l[head+1].st))<esp)
return;
while(head<tail&&(((l[tail]&l[tail-1])-line[i].st)^(line[i].ed-line[i].st))>esp)
tail--;
while(head<tail&&(((l[head]&l[head+1])-line[i].st)^(line[i].ed-line[i].st))>esp)
head++;
l[++tail]=line[i];
}
while(head<tail&&(((l[tail]&l[tail-1])-l[head].st)^(l[head].ed-l[head].st))>esp)
tail--;
while(head<tail&&(((l[head]&l[head-1])-l[tail].st)^(l[tail].ed-l[tail].ed))>esp)
head++;
if(tail<=head+1)
return;
for(int i=head; i<tail; i++)
res[resn++]=l[i]&l[i+1];
if(head<tail-1)
res[resn++] = l[head]&l[tail];
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
reverse(p,p+n);
for(int i=0; i<n; i++)
l[i]=line(p[i],p[(i+1)%n]);
int resn;
hpi(l,n,p,resn);
if(resn<3)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}