zoukankan      html  css  js  c++  java
  • 两线段是否相交模板

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 struct point
     4 {
     5     int x,y;
     6 }p1,p2,p3,p4;
     7 int cross(const point &a,const point &b,const point &o)
     8 {
     9     return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y);
    10 }
    11 bool work(const point &a,const point &b,const point &c,const point &d)
    12 {
    13     return ((cross(a,d,c)*cross(d,b,c)>=0)&&(cross(c,b,a)*cross(b,d,a)>=0)
    14             &&(max(c.x,d.x)>=min(a.x,b.x))&&(max(a.x,b.x)>=min(c.x,d.x))
    15             &&(max(c.y,d.y)>=min(a.y,b.y))&&(max(a.y,b.y)>=min(c.y,d.y)));
    16 }
    17 int main()
    18 {
    19     while(scanf("%d%d%d%d%d%d%d%d",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y)!=EOF)
    20     {
    21         if(work(p1,p2,p3,p4)) puts("YES");
    22         else puts("NO");
    23     }
    24     return 0;
    25 }
    View Code
  • 相关阅读:
    centos 7 安装maven
    linux添加用户
    intellij添加jar包
    mysql用户管理
    centos7 mariaDB安装
    hibernate入门实例
    Linux文件描述符
    Python小爬虫实例
    IO流-文件管理
    IO流-ZIP文档
  • 原文地址:https://www.cnblogs.com/CJLHY/p/7899625.html
Copyright © 2011-2022 走看看