POJ 3130 How I mathematician Wonder what do you are!

Source: Internet
Author: User

How I mathematician Wonder what are you are!
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 3568 Accepted: 1906

Description

After counting so many stars in the sky in He childhood, ISAAC, now an astronomer and a mathematician uses a big astronom ical telescope and lets his image processing program Count stars. The hardest part of the program was to judge if shining object in the sky is really a star. As a mathematician, the only-the-knows is to apply a mathematical definition of stars.

The mathematical definition of a star shape is as follows:a planar shape F are star-shaped if and only I F there is a point c∈ f Such this, for any point p∈ f, the line segment CP are contained in F. Such a point C is called a center of F. To get accustomed to the definition let's see some examples below.

The first and the would normally call stars. According to the above definition, however, all shapes in the first row is star-shaped. The second row is not. For each star shape, the a center is indicated with a dot. Note that a star shape in the general have infinitely many centers. Fore Example, for the third quadrangular shape, all points in it is centers.

Your job is-to-write a program, tells whether a given polygonal shape is star-shaped or not.

Input

The input is a sequence of datasets followed to a line containing a single zero. Each dataset specifies a polygon, and is formatted as follows.

N
x1 y1
x2 y2

...

Xn Yn

The first line is the number of vertices,  n , which satisfies 4≤  n  ≤50. subsequent  n  lines is the  x -and  y -coordinates of the  N  vertices. They is integers and satisfy 0≤  XI  ≤10000 and 0≤  Yi ≤10000 ( i  = 1, ..., &N Bsp n ). Line segments ( Xi ,   Yi ) – ( XI  + 1,  yi  + 1) ( I  = 1, ...,   n  −1) and the line segment ( xn ,   yn ) – ( x 1,  y 1) Form the border of the polygon in the counterclockwise order. That's, these line segments see the inside of the polygon in the left of their directions.

You may assume the polygon are simple , that's, its border never crosses or touches itself. Assume assume that no three edges of the polygon meet at a single point even when they is infinitely extended.

Output

For each dataset, output " 1 if the polygon is star-shaped and" 0 "otherwise. Each number must is in a separate line and the line should not contain any other characters.

Sample Input

6 66 13 96 61 76 98 13 94 4 0 45 68 8 27 21 55 14 93 12 56 95 15 48 38 46 51 65 64 31 0

Sample Output

10

/*poj 3130 How do I mathematician Wonder What do you are! each time give you a shape to judge whether it is a star if it is a star, Then there must be a point where all the dots in the graph are connected to it in the graph class, that is, if there is a point where you can observe all the positions of the graphic hhh-2016-05-11 20:28:01*/#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 Std;const int maxn = 1010;const double PI =    3.1415926;const double eps = 1e-8;int sgn (double x) {if (Fabs (x) < EPS) return 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 P0; Point LIS[MAXN]; Line LINE[MAXN];d ouble Dist (point A,point b) {return sqrt ((a) * (-a));} BOOL CMP (point A,point b) {Double t = (a-p0) ^ (b-p0);    if (SGN (t) > 0) return true;    else if (SGN (t) = = 0 && sgn (Dist (a,lis[0])-dist (B,lis[0])) <= 0) return true; else return false;}    int main () {//Freopen ("In.txt", "R", stdin);    int n; while (scanf ("%d", &n)! = EOF && N) {for (int i = 0; i < n; i++) {scanf ("%LF%LF"        , &AMP;LIS[I].X,&AMP;LIS[I].Y);        } 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 ("1\n");    else printf ("0\n"); } return 0;}

  

POJ 3130 How I mathematician Wonder what do you are!

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.