Area Separation
Time limit8sMemory limit512 MB
Given lines that each cut a fixed square, count how many regions the square is divided into.
- Level
Medium6 of 10
- Topics
- Geometry, Implementation, Sorting, Hash map
- Solved
- No attempts yet
Problem
Mr. Yamada Springfield Tanaka has been entrusted with the weighty post of Deputy Assistant to the Director of the National Land Readjustment Bureau. His country is in the middle of a large-scale land readjustment, and if he can bring it to a smooth finish, his promotion is said to be certain.
However, there are many who do not take kindly to his rise. One of them is Mr. Sato Seabreeze Suzuki. He has schemed to trip up Mr. Yamada at every opportunity. This time too, to trip him up, Mr. Sato pressured the organization actually carrying out the land readjustment, and made the results of the readjustment extremely hard to read.
So the result handed to Mr. Yamada contained only information about which lines divided a certain square piece of land. If he cannot at least find out how many pieces that square land was divided into, then rather than a promotion, Mr. Yamada will certainly be fired.
Your job is to write a program that investigates how many pieces the square region with vertices (-100,-100), (100,-100), (100,100), (-100,100) is divided into by the given n lines, and to save Mr. Yamada from the threat of dismissal.
Input
The input consists of multiple test cases.
The first line of each test case gives an integer n, the number of lines (1 ≤ n ≤ 100). The following n lines each contain four integers x1, y1, x2, y2. These integers represent two distinct points (x1, y1) and (x2, y2) on a line. The two given points are always guaranteed to be points on the sides of the square. The n given lines are all distinct, and no two lines overlap. Also, no line overlaps a side of the square.
The end of the input is indicated by n = 0.
Output
For each test case, output the number of regions divided by the n lines on a single line.
Two points whose distance is less than 10-10 may be regarded as coinciding. Also, there is no pair of intersection points P, Q, R with |PQ| < 10-10, |QR| < 10-10, and |PR| >= 10-10.