Jaeha's Toy
Time limit1sMemory limit1024 MB
Given a closed polyline whose segments may cross each other, count the bounded regions with positive area that it forms.
- Level
Medium6 of 10
- Topics
- Geometry, Graph, Implementation
- Solved
- No attempts yet
Problem
Jaeha is a star baby who was born not long ago, and he grew up in no time. He is so curious, like whoever he takes after, that he keeps reaching out to touch things around him. Jaeha's father and mother bought him a toy for this. The toy is a ring of line segments joined end to end, so it is hard for a baby to put in his mouth.

Jaeha got mischievous and began twisting the toy into all sorts of shapes, like these.

Strictly speaking, the toy is a polygon defined by the points , , , , and back to , where adjacent points are joined by line segments. The segments may cross each other.
Count the regions with an area greater than 0 that the toy forms. The infinite outer region that existed from the start is not counted.
Input
The input consists of test cases. The first line contains .
The first line of each test case contains (), the number of vertices of the toy. The next lines each contain the coordinates and () of a vertex. Within a test case, no two vertices have the same coordinates.
Output
For each test case, print on its own line the number of regions described in the problem.