After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if shining object in the sky is really a star. As a mathematician, the only way he knows is to apply a mathematical definition of stars.
The mathematical definition of a star shape is as follows: A planar shape $F$ is star-shaped if and only if there is a point $C \in F$ such that, for any point $P \in F$, the line segment $CP$ is 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 two are what you would normally call stars. According to the above definition, however, all shapes in the first row are star-shaped. The two in the second row are not. For each star shape, a center is indicated with a dot. Note that a star shape in general has infinitely many centers. Fore Example, for the third quadrangular shape, all points in it are centers.
Your job is to write a program that tells whether a given polygonal shape is star-shaped or not.
Input
The input is a sequence of datasets followed by 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 \le n \le 50$. Subsequent $n$ lines are the $x$- and $y$-coordinates of the $n$ vertices. They are integers and satisfy $0 \le x_i \le 10000$ and $0 \le yi \le 10000 (i = 1, …, n)$. Line segments $(x_i, y_i)–(x_{i + 1}, y_{i + 1}) (i = 1, …, n − 1)$ and the line segment $(x_n, y_n)–(x_1, y_1)$ form the border of the polygon in the counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions.
You may assume that the polygon is simple, that is, its border never crosses or touches itself. You may assume 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 number must be in a separate line and the line should not contain any other characters.
classPoint { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} inlinevoidinput(){ scanf("%lf%lf", &x, &y); } booloperator<(const Point &a) const { return (!dcmp(x - a.x))? dcmp(y - a.y) < 0: x < a.x; } booloperator==(const Point &a) const { return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0; } db dis2(const Point a){ returnpow(x - a.x, 2) + pow(y - a.y, 2); } db dis(const Point a){ returnsqrt(dis2(a)); }
db dis2(){ return x * x + y * y; } db dis(){ returnsqrt(dis2()); } Point operator+(const Point a) { return Point(x + a.x, y + a.y); } Point operator-(const Point a) { return Point(x - a.x, y - a.y); } Point operator*(double p) { return Point(x * p, y * p); } Point operator/(double p) { return Point(x / p, y / p); } db dot(const Point a){ return x * a.x + y * a.y; } db cross(const Point a){ return x * a.y - y * a.x; } db ang(Point a){ returnacos((a.dis() * dis()) / dot(a)); } }; typedef Point Vector;