#P8720. Counting Regions Divided by Lines
Counting Regions Divided by Lines
Counting Regions Divided by Lines
You are given N lines on the plane. The i-th line is given by the equation \(y = A_i \cdot x + B_i\). These lines partition the plane into several regions. Your task is to compute the number of regions created by these N lines.
Note: Some lines may be parallel and there can be cases where more than two lines intersect at the same point (i.e. concurrent lines). When adding a new line, it divides the plane into as many new regions as the number of distinct intersection points it makes with all previous lines plus one.
A hint for solving the problem is to initialize the number of regions to 1 (which is the region before any line is added) and then for every new line, find the number of distinct intersection points with earlier lines. The total regions will be updated as follows: \[ regions \mathrel{+}= (\text{number of distinct intersections}) + 1. \]
inputFormat
The first line contains an integer \(N\) representing the number of lines. Each of the following \(N\) lines contains two integers \(A_i\) and \(B_i\) (separated by space), representing the parameters of the \(i\)-th line: \(y = A_i \cdot x + B_i\).
outputFormat
Output a single integer, the number of regions into which the plane is divided by the given lines.
sample
1
1 0
2