Find the intersections
Practice
0 (0 votes)
Line segment
Medium
Geometry
Line sweep technique
Implementation
Line intersection using bentley ottmann algorithm
Algorithms
Mathematics
Math
Problem
27% Success 22 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a set of \(N\) line segments that are either horizontal or vertical. Write a program to determine the points of intersection of all the horizontal line segments with the vertical line segments.
Note: Do not consider the coincident endpoints as intersections.
Input format
- First line: \(N\)
- Next \(N\) lines: Four space-separated integers, \(x1\), \(y1\), \(x2\), and \(y2\) denoting the coordinates of two line segments
Output format
Sort and print all the intersection points of the horizontal and the vertical line segments. The intersection point is represented as \((x,\ y)\) with space between them.
Constraints
\(1 ≤ N ≤ 10^{3}\)
For horizontal line:
\(1 ≤ x1 < x2 ≤ 10^{6}\)
\(1 ≤ y1 = y2 ≤ 10^{6}\)
For vertical line:
\(1 ≤ x1 = x2 ≤ 10^{6}\)
\(1 ≤ y1 < y2 ≤ 10^{6}\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
1.AABBAAC
Points:30
17 votes
Tags:
ApprovedImplementationMediumOpenString Manipulation
Points:50
12 votes
Tags:
Ad-HocDSUData StructuresDisjoint Data StructuresDisjoint SetHard難しい
Points:20
426 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyOpen
Editorial
Login to unlock the editorial