POJ 3335 Rotating Scoreboard (semi-flat cross)

Source: Internet
Author: User

Rotating Scoreboard
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6420 Accepted: 2550

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 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 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

0 0 0 1 1 1 1 0 0  0 2  1 2  1 1  2 1  2 2  3 2  3 0

Sample Output

YESNO

/*poj 3335 Rotating Scoreboard (semi-planar intersection) give a graph to determine if there is a position to observe all the positions within the graph that is, the core input of a graph is clockwise and needs to be inverted hhh-2016-05-08 21:18:33*/# Include <iostream> #include <vector> #include <cstring> #include <string> #include <cstdio > #include <queue> #include <cmath> #include <algorithm> #include <functional> #include < map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef long Long ll;using namespace St d;const int maxn = 1010;const double PI = 3.1415926;const double eps = 1e-8;int sgn (double x) {if (Fabs (x) < EPS) re    Turn 0;    if (x < 0) return-1; else return 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-y*b.x; } Double operator * (const point &b) Const {return x*b.x + y*B.Y;    }};struct line{Point s,t;    Double k;        Line () {} line (point _s,point _t) {s = _s;        t = _t;    K = atan2 (t.y-s.y,t.x-s.x);        } Point operator & (const line &b) Const {Point res = s;        Double Ta = ((S-B.S) ^ (b.s-b.t))/((s-t) ^ (b.s-b.t));        Res.x + = (t.x-s.x) *ta;        Res.y + = (t.y-s.y) *ta;    return res;    }};bool hpicmp (line A,line b) {if (Fabs (A.K-B.K) > EPS) return a.k<b.k; Return ((A.S-B.S) ^ (B.T-B.S) < 0;}    Line Li[maxn];void HPI (line line[],int n,point res[],int &resn) {int tot =n;    Sort (line,line+n,hpicmp);    tot = 1;    for (int i = 1; i < n; i++) {if (Fabs (LINE[I].K-LINE[I-1].K) > EPS) line[tot++] = Line[i];    } int head = 0,tail = 1;    Li[0] = line[0];    LI[1] = line[1];    RESN = 0;                for (int i = 2; i < tot; i++) {if (Fabs ((LI[TAIL].T-LI[TAIL].S) ^ (LI[TAIL-1].T-LI[TAIL-1].S)) < eps| | Fabs ((LI[HEAD].T-LI[HEAD].S) ^ (li[HEAD+1].T-LI[HEAD+1].S) < EPS) return; while (Head < tail && (((Li[tail] & Li[tail-1])-LINE[I].S) ^ (LINE[I].T-LINE[I].S)) > EPS) t        ail--; while (Head < tail && (((Li[head] & li[head+1])-LINE[I].S) ^ (LINE[I].T-LINE[I].S)) > EPS) H        ead++;    Li[++tail] = Line[i];        } while (Head < tail && (((Li[tail] & Li[tail-1])-LI[HEAD].S) ^ (LI[HEAD].T-LI[HEAD].S)) > EPS)    tail--; while (Head < tail && (((Li[head] & li[head-1)-Li[tail].s) ^ (li[tail].t-li[tail].t)) > EPS) he    ad++;    if (tail <= head+1) return;    for (int i = Head;i < tail;i++) res[resn++] = li[i]&li[i+1]; if (Head < TAIL-1) res[resn++] = Li[head]&li[tail];} Point LIS[MAXN];    Line Line[maxn];int Main () {//freopen ("In.txt", "R", stdin);    int n,t;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);    for (int i = 0;i < n;i++)    {scanf ("%lf%lf", &lis[i].x,&lis[i].y);        } reverse (Lis,lis+n);        int ans;        for (int i = 0;i < n;i++) {Line[i] = line (lis[i],lis[(i+1)%n]);        } HPI (Line,n,lis,ans);        if (ans) printf ("yes\n");    else printf ("no\n"); } return 0;}

  

POJ 3335 Rotating Scoreboard (semi-flat cross)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.