Skip to content
Discussion options

You must be logged in to vote

We need to count trapezoids (quadrilaterals with at least one pair of parallel sides) from given points.

Approach:

  • Precompute all point pairs (i, j) → each pair defines a segment.

  • For each pair:

    • Compute the normalized slope (dy, dx); vertical lines treated separately.
    • Compute the normalized line equation (A, B, C) as the signature of that infinite line.
    • Compute the midpoint signature (x₁ + x₂, y₁ + y₂) without division (for parallelogram detection).
  • Maintain:

    • cnt1[slope][lineSignature]
      → counts how many segments lie on the same infinite line with same slope
      → used to count pairs of parallel but non-collinear segments (candidate trapezoid bases).
    • cnt2[midpointSignature][slope]
      → c…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 3, 2025
Maintainer Author

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Dec 3, 2025
Maintainer Author

@mah-shamim
Comment options

mah-shamim Dec 3, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
1 participant