Cut the Cake
Time limit20sMemory limit128 MB
Count into how many regions the given infinite lines divide a circle.
- Level
Medium5 of 10
- Topics
- Geometry, Combinatorics
- Solved
- No attempts yet
Problem
You are given a circle and a list of lines. Count how many parts the lines cut the circle into.
Every line extends infinitely in both directions. A line that never meets the circle does not cut it.
Input
The input has several test cases. Each test case begins with four integers (), , (), and (). Here is the radius of the circle, is its center, and is the number of lines.
Each of the next lines contains four integers , , , (). These four integers describe the line through and . What matters is the whole infinite line, not the segment between the two points.
In every test case, no more than two lines meet at any point inside the circle, no line is tangent to the circle, and no two lines are the same line.
The input ends with a line of four zeros.
Output
For each test case, print a single integer on its own line: the number of parts the circle is cut into. Print no spaces and no blank lines.