1264 segment intersection base time limit: 1 second space limit: 131072 KB score: 0 Difficulty: Basic Topic Collection Attention Description
The two endpoints of two segments on the plane are given to determine if the two segments intersect (there is a common point or some overlap is considered intersecting). If it intersects, output "Yes", otherwise output "No".
Input
Line 1th: A number T, indicating the number of tests entered (1 <= T <= 1000)
2-t + 1 lines: 8 numbers per line, X1,y1,x2,y2,x3,y3,x4,y4. ( -10^8 <= xi, Yi <= 10^8)
(Two endpoints of line 1 are x1,y1 | x2, y2, two endpoints of line 2 are X3,y3 | x4, Y4)
Output
Output a total of t lines, or output "No" if the intersection output is "Yes".
Input example
2
1 2 2 1 0 0 2 2
-1 1 1 1 0 0 1-1
Output example
Yes
No
Exercises
Determine whether the segments intersect by judging the cross product. The code is as follows:
#include <cstdio>#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <map>#include <set>#include <queue>#include <utility>#define ll long longusing namespace std ;struct point {double x , y ;} ;double xmul ( point a , point b , point c ){ return ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x ) ;}int main(){ int t ; cin >> t ; while ( t -- ){ point a , b , c , d ; cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y ; if ( xmul(a , b , c) * xmul(a , b , d) <= 0 && xmul(c , d , a) * xmul(c , d , b) <= 0 ){ cout << "Yes" << endl ; }else{ cout << "No" << endl ; } } return 0 ;}
51Nod 1264 segment Intersection