zoukankan      html  css  js  c++  java
  • ZOJ1648 Circuit Board(线段相交)

    裸的判断线段相交

     1 #include <map>
     2 #include <set>
     3 #include <stack>
     4 #include <queue>
     5 #include <cmath>
     6 #include <ctime>
     7 #include <vector>
     8 #include <cstdio>
     9 #include <cctype>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <iostream>
    13 #include <algorithm>
    14 using namespace std;
    15 #define eps 1e-12
    16 #define MAXN 2005
    17 #define INF 1000000007
    18 #define MAX(a,b) (a > b ? a : b)
    19 #define MIN(a,b) (a < b ? a : b)
    20 #define mem(a) memset(a,0,sizeof(a))
    21 
    22 struct Point{
    23     double x,y;
    24     Point(double x=0, double y=0):x(x),y(y){}
    25 };
    26 
    27 double Cross(Point A, Point B) { return A.x*B.y - A.y*B.x;}//叉积
    28 
    29 int N;
    30 struct LINE
    31 {
    32     Point s, e;
    33 } Line[MAXN];
    34 
    35 int main()
    36 {
    37     while(~scanf("%d", &N))
    38     {
    39         for(int i=0;i<N;i++)
    40         {
    41             scanf("%lf%lf%lf%lf", &Line[i].s.x, &Line[i].s.y, &Line[i].e.x, &Line[i].e.y);
    42         }
    43         int ok = 1;
    44         for(int i=0;i<N && ok;i++)
    45         {
    46             Point Pi = Point(Line[i].e.x-Line[i].s.x, Line[i].e.y-Line[i].s.y);
    47             for(int j=i+1;j<N && ok; j++)
    48             {
    49                 double c1 = Cross(Point(Line[j].s.x-Line[i].s.x, Line[j].s.y-Line[i].s.y), Pi);
    50                 double c2 = Cross(Point(Line[j].e.x-Line[i].s.x, Line[j].e.y-Line[i].s.y), Pi);
    51                 if(c1 * c2 < 0)
    52                 {
    53                     Point Pj = Point(Line[j].e.x-Line[j].s.x, Line[j].e.y-Line[j].s.y);
    54                     c1 = Cross(Point(Line[i].s.x-Line[j].s.x, Line[i].s.y-Line[j].s.y), Pj);
    55                     c2 = Cross(Point(Line[i].e.x-Line[j].s.x, Line[i].e.y-Line[j].s.y), Pj);
    56                     if (c1 * c2 < 0) ok = 0;
    57                 }
    58             }
    59         }
    60         printf("%s
    ",ok?"ok!":"burned!");
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    element ui el-date-picker 判断所选时间是否交叉
    MDN中的箭头函数!!!
    es6 解构
    element ui 实现可编辑表格
    节流 防抖。。。。深入理解
    element ui 表格对齐方式,表头对齐方式
    纯html + css 导航栏
    PHP 1
    apache 建立虚拟主机
    Can't connect to local MySQL server through socket '/tmp/mysql.sock'
  • 原文地址:https://www.cnblogs.com/gj-Acit/p/3273387.html
Copyright © 2011-2022 走看看