问题3787--Simple Polygon

3787: Simple Polygon

[命题人 : ]
时间限制 : 3.000 sec  内存限制 : 64 MB

题目描述

A polygon P determined by points p1, p2, . . . , pn is a closed chain of line segments (callededges) p1p2, p2p3, . . . , pnp1 in the plane. Polygon P is simple, if no two edges have any pointsin common, with the obvious exception of two consecutive segments having one common point(called vertex). Note however, that if a vertex is part of any other (third) edge, the polygon isno longer simple.Any polygon that is not simple is called self-intersecting. In two example figures below, the firstpolygon is simple, the second one is self-intersecting Your task is to determine whether a given polygon is simple or self-intersecting

输入

The input contains several test cases. Each test case corresponds to one polygon. First line ofthe test case contains N , the number of points (1 ≤ N ≤ 40 000). Each of the following N linescontains coordinates of point Pi, that is Xi, Yi separated by space, 1 ≤ Xi, Yi ≤ 30 000.The last test case is followed by a line containing zero.

输出

For each test case output either "YES" (the polygon is simple) or "NO" (the polygon is self-intersecting).

样例输入 Copy

5
1 6
5 7
9 4
2 3
6 1
7
1 6
5 7
9 4
4 3
7 4
4 6
3 1
7
1 1
1 4
1 3
2 2
3 1
3 3
2 2
0

样例输出 Copy

NO
YES
NO

来源/分类