report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Line segment intersection - MarisaOJ: Marisa Online Judge

Line segment intersection

Time limit: 1000 ms
Memory limit: 256 MB
Given $q$ questions. In each question, you are given four points $A(x_A,y_A),B(x_B,y_B),C(x_C,y_C),D(x_D,y_D)$. Determine if line segment $AB$ intersect with line segment $CD$ (i.e. they have at least one common point). It is guaranteed that $A \neq B$ and $C \neq D$. ### Input - The first line contains an integer $q$. - The next $q$ lines, each line contains eight integers $x_A,y_A,x_B,y_B,x_C,y_C,x_D,y_D$. ### Output - Print $q$ lines. Each line, print `YES` if two line segments in the corresponding question interesect, otherwise print `NO`. ### Constraints - $1 \le q \le 10^5$. - $-10^9 \le x, y \le 10^9$. ### Example Input: ``` 5 1 1 5 3 1 2 4 3 1 1 5 3 1 1 4 3 1 1 5 3 2 3 4 1 1 1 5 3 2 4 4 1 1 1 5 3 3 2 7 4 ``` Output: ``` NO YES YES YES YES ```
Geometry
Three points
Line segment intersection
Line intersection
Quadrilateral classification
Point location
Triangle classification
Polygon area
Distance to polygon
Convex hull
Perpendicular pairs
Maximum quadrilateral
Catching butterflies
Topic
Geometry
Rating 1100
Source CSES
Solution (1) Solution