51Nod 1264 segment Intersection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.