How I Mathematician Wonder What You Are!

Time limit1sMemory limit128 MB

Summary
Determine whether a given simple polygon is star-shaped by computing the intersection of half-planes defined by its edges (kernel of polygon).
Level

Medium7 of 10

Topics
Geometry, Intervals, Implementation
Solved
No attempts yet

Problem

After counting so many stars in the sky as a child, Isaac, now an astronomer and mathematician, uses a large astronomical telescope and lets his image-processing program count stars. The hardest part of the program is judging whether a shining object in the sky is really a star. As a mathematician, the only way he knows is to apply a mathematical definition of a star.

The mathematical definition of a star shape is as follows. A planar shape FF is star-shaped if and only if there is a point C∈FC \in F such that, for every point P∈FP \in F, the line segment CPCP is contained in FF. Such a point CC is called a center of FF.

By this definition, not only the stars you would normally draw but many other shapes are star-shaped as well. A star-shaped region in general has infinitely many centers; for a convex polygon, for instance, every point of the polygon is a center.

Your job is to write a program that decides whether a given polygonal shape is star-shaped.

Input

The input is a sequence of datasets, followed by a line containing a single zero. Each dataset specifies a polygon in the following format:

n
x1 y1
x2 y2
...
xn yn

The first line is the number of vertices nn, which satisfies 4≤n≤504 \le n \le 50. The next nn lines give the xx- and yy-coordinates of the nn vertices; they are integers and satisfy 0≤xi≤100000 \le x_i \le 10000 and 0≤yi≤100000 \le y_i \le 10000 (i=1,…,ni = 1, \ldots, n). The line segments (xi,yi)(x_i, y_i)–(xi+1,yi+1)(x_{i+1}, y_{i+1}) (for i=1,…,n−1i = 1, \ldots, n-1) and the line segment (xn,yn)(x_n, y_n)–(x1,y1)(x_1, y_1) form the border of the polygon in counterclockwise order; that is, each segment has the inside of the polygon on the left of its direction.

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

Output

For each dataset, output 1 if the polygon is star-shaped and 0 otherwise. Each answer must be on its own line, and the line must contain no other characters.

Examples1

  1. Example 1

    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
    
    Expected output
    1
    0