Number of Polygons
Time limit2sMemory limit128 MB
Given up to 50 lines defined by point pairs, compute the number of bounded convex polygonal regions formed by their arrangement.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Union-find, Combinatorics
- Solved
- No attempts yet
Problem
A very large sheet of paper is identified with the XY coordinate plane. Dasom drew N straight lines on it. Each input row gives two distinct points, and the full straight line passing through those points is drawn.
The drawn lines partition the plane into regions. Every bounded region in a line arrangement is a convex polygon whose interior is not crossed by any drawn line. Given the two points that determine each line, compute how many such polygonal regions are formed.
Input
The first line contains the number of lines N. N is a positive integer not greater than 50.
Each of the next N lines contains four integers x1, y1, x2, y2: the coordinates of two distinct points on one line, in order. Every coordinate is between -10,000 and 10,000 inclusive. No input line description is repeated exactly.
Output
Print the number of polygonal regions.