Crossing Segments
Count the pairs of line segments that intersect (touching at an endpoint or overlapping counts as intersecting).
Input: the first line has N; each of the next N lines has a segment x1 y1 x2 y2.
Output: the number of intersecting pairs.
Constraints:
- 1 ≤ N ≤ 103
- |coordinates| ≤ 104
Sample Tests
Input 1
3 0 0 4 4 0 4 4 0 5 5 6 6
Output 1
1
Input 2
2 0 0 1 1 2 2 3 3
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.