Rotating Scoreboard
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 7085 |
|
Accepted: 2835 |
Description
This year, ACM/ICPC World Finals would 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 are not blocked by a wall). Note that if the line of sight of a spectator are tangent to the polygon boundary (either in a vertex or on an edge), he CA N 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 are a location for the Scoreboard (a point inside the polygon) such that the scoreboard can is viewed from any point on the edges of the polygon .
Input
The first number in the input line, and T is the number of the test cases. Each test case was specified on a single line of input in the form n x1y1x2y2 ... 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 of corresponding to a input test case in this order. The output line contains either YES or NO depending on whether the scoreboard can is 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 Tehran 2006 Preliminary
"Analysis" half-plane intersection ... Same as the last. Only this time the point pair turned clockwise, the corresponding judgment to reverse. In fact, if the topic did not tell whether it is shun or inverse as long as the point to the pros and cons to run all over it.
PS: Cross product >0, Dot to the left of the vector. Otherwise on the right side
Code
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <
Cmath> #define EPS 1e-8 #define LL Long long #define FO (i,j,k) for (i=j;i<=k;i++) using namespace std;
const int mxn=50005;
int n,h,t,ln,t;
int ORDER[MXN],QUE[MXN];
struct point {double x, y;} P[MXN];
struct Line {point a,b;double ang;} L[MXN];
inline int sign (double k) {if (Fabs (k) <eps) return 0;
Return k>0?1:-1; } Inline Double Cross (point p0,point p1,point p2) {return (p1.x-p0.x) * (P2.Y-P0.Y)-(p2.x-p0.x) * (P1.Y-P0.Y);} inline bool
comp (int u,int v) {int d=sign (L[u].ang-l[v].ang);
if (!d) return sign (Cross (l[u].a,l[v].a,l[v].b)) <0;
Return d<0;
} inline void get (line l1,line l2,point &p) {double d1,d2;
D1=cross (l2.a,l1.b,l1.a);
D2=cross (l1.b,l2.b,l1.a);
p.x= (L2.A.X*D2+L2.B.X*D1)/(D1+D2);
p.y= (L2.A.Y*D2+L2.B.Y*D1)/(D1+D2);
} inline bool Judge (line L0,line L1,line L2) {point P;
Get (L1,L2,P);
Return sign (p,l0.a,l0.b) >0; } inline voidPHI () {int i,j;
Sort (order,order+ln,comp);
for (i=1,j=0;i<ln;i++) if (sign (L[order[i]].ang-l[order[j]].ang) >0) order[++j]=order[i];
Ln=j,h=0,t=1;
QUE[0]=ORDER[0],QUE[1]=ORDER[1];
Fo (I,2,LN) {while (h<t && judge (L[order[i]],l[que[t-1]],l[que[t])) t--;
while (h<t && judge (L[order[i]],l[que[h+1]],l[que[h])) h++;
Que[++t]=order[i];
} while (H<t && judge (L[order[h]],l[que[t-1]],l[que[t])) t--;
while (h<t && judge (L[order[t]],l[que[h+1]],l[que[h])) h++;
} inline void AddLine (double x1,double y1,double x2,double y2) {l[ln].a.x=x1,l[ln].a.y=y1;
L[ln].b.x=x2,l[ln].b.y=y2;
L[ln].ang=atan2 (X2-X1,Y2-Y1);
order[ln]=ln,ln++;
} int main () {int i,j;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
Fo (i,0,n-1) scanf ("%lf%lf", &p[i].x,&p[i].y);
for (ln=i=0;i<n-1;i++) addline (P[I].X,P[I].Y,P[I+1].X,P[I+1].Y);
AddLine (P[I].X,P[I].Y,P[0].X,P[0].Y);
PHI ();
if (t-h>1) printf ("yes\n"); Else priNTF ("no\n");
} return 0; }