51nod 1264 segment Intersection (the intersection of segments, including endpoints and partial overlap)

Source: Internet
Author: User

1264 segment intersection base time limit: 1 seconds space limit: 131072 KB score: 0 Difficulty: The base collection focuses on the two endpoints of two segments on the plane, judging if the two segments intersect (there is a common point or partial 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
21 2 2 1 0 0 2 2-1 1 1 1 0 0 1-1
Output example
YesNo
Li Tao(topic Provider)

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h> #include <math.h> #define EPS 1e-8#define Zero (x) (((x) > 0? (x): (-X)) < EPS) using namespace std;struct point {double X, y;}; struct Line {point a b;}; Double Xmult (Point P1,point p2,point p) {return (p1.x-p.x) * (P2.Y-P.Y)-(p2.x-p.x) * (P1.Y-P.Y);} int dot_online_in (Point p,line L) {return zero (Xmult (p,l.a,l.b)) && (l.a.x-p.x) * (l.b.x-p.x) < EPS &&am P (L.A.Y-P.Y) * (L.B.Y-P.Y) < EPS;} int Dot_inline (point p1,point p2,point p3) {return zero (Xmult (P1,P2,P3));} int Same_side (point p1,point p2,line l) {return Xmult (l.a,p1,l.b) *xmult (l.a,p2,l.b) >eps;} int intersect_in (line U,line v) {if (!dot_inline (U.A,U.B,V.A) | |!dot_inline (U.A,U.B,V.B)) {return!same_side (u.a    , u.b,v) &&!same_side (v.a,v.b,u); } return dot_online_in (u.a,v) | | Dot_online_in (u.b,v) | | Dot_online_in (v.a,u) | | Dot_online_in(V.b,u);}    int main () {int T;    scanf ("%d", &t);        while (t--) {line u,v; scanf ("%lf%lf%lf%lf%lf%lf%lf%lf", &u.a.x,&u.a.y,&u.b.x,&u.b.y,&v.a.x,&v.a.y,&v.b.x,        &AMP;V.B.Y);        int flag = intersect_in (U,V);        if (flag = = 1) {printf ("yes\n");        } else {printf ("no\n"); }} return 0;}


Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

51nod 1264 segment Intersection (the intersection of segments, including endpoints and partial overlap)

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.