Simple Polygon
Time limit10sMemory limit128 MB
Given up to 40,000 points defining a closed polygon, decide whether its edges only meet at shared endpoints (simple) or intersect anywhere (NO).
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Divide and conquer, Brute force
- Solved
- No attempts yet
Problem
A polygon defined by points in the plane is the closed chain of line segments (called edges) . The polygon is simple if no two edges share any point, with the single exception that two consecutive edges may share their one common point (called a vertex). However, if a vertex also lies on any other (third) edge, the polygon is no longer simple.
A polygon that is not simple is called self-intersecting.
Your task is to determine whether a given polygon is simple or self-intersecting.
Input
The input contains several test cases; each test case describes one polygon. The first line of a test case contains , the number of points (). Each of the next lines contains the coordinates of a point , namely and separated by a space (). The points are given in the order they appear along the polygon.
The last test case is followed by a line containing a single , which marks the end of the input.
Output
For each test case, print YES on its own line if the polygon is simple, or NO if it is self-intersecting.