Find the Intersections

5

1 votes
Geometry, Mathematics, Line Sweep Technique, Easy-Medium, Line segment, Mathematics
Problem

Given a set of N line segments, you need to find all the intersection points of all the horizontal line segments with all the vertical line segments.Don't consider the coincident endpoints as intersections.

Input:
First line consists of N denoting the number of line segments.
Following N lines consist of x1,y1,x2,y2 each where (x1,y1) represents the starting point of line segment and (x2,y2) represents the ending point of line segment.
The line segments would either be horizontal or vertical.

Output:
Print all the intersection points as asked in the question in a separate line in sorted order.The intersection point is represented as (x,y) with space between them.See the sample output for clarity.

Constraints:
1N103
For horizontal line:
1x1 < x2106
1y1 = y2106
For vertical line:
1x1 = x2106
1y1 < y2106

Sample Input
3
1 2 4 2
2 1 2 3
3 1 3 3
Sample Output
2 2
3 2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The intersections are (2,2) and (3,2)

Contributers:
Editor Image

?