74 - ZOJ Monthly, January 2009 - I
In World War 3, your countries' scientists have invented a special weapon. Assume that the enemy's city can be described by rectangular coordinates and it has n roads which are all lines. None of the road is paralled with Y-axis. Besides, each road is represented by two different points (ai,bi) (ci,di) on it. Any three roads will not intersect at one point.
This special weapon can destroy all the castles whose x coordinate belongs to (l,r). After spying, you know that all the castles are set in the crossing point of two roads and in each crossing point there is a castle. In addition, each road's end-point's x coordinate does not belong to (l,r).
The scientists want to check the weapon's effect. If its effect can not reach army's expectation, they have to spend more time and more money in expanding its range. Obviously, the number of castles it can destroy plays an important role on the effect. So you are asked to calculate how many castles can be destroyed by this special weapon.
Input contains multiple cases.
Every test case, the first line is an integers n (2 <= n <= 10000). Then n lines follow. The (i+1)-th line contains four integers ai,bi,ci,di (-1E8 <= ai,bi,ci,di <= 1E8). The (n+2)-th line contains two doubles l,r (-1E8 <= l,r <= 1E8) There is a blank line between two cases.
For each case, output the number of castles that can be destroyed by the weapon.
3 0 0 1 1 2 0 1 1 0 0 2 0 0 2.5
Author: MO, Luyi
Source: ZOJ Monthly, January 2009