zoj1648

不知道怎么判断两条线段相交,学习学习吧

#include <queue>   
#include <stack>   
#include <math.h>   
#include <stdio.h>   
#include <stdlib.h>   
#include <iostream>   
#include <limits.h>   
#include <string.h>   
#include <algorithm>   
using namespace std;  
const double eps = 0.00;  
typedef struct Point{  
        double x,y;  
}Point;  
typedef struct Line{  
        Point a,b;  
}Line;  
double Direction(Point a, Point b, Point c )  
{  
       return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);  
}  
bool onSegment(Point a, Point b, Point c)  
{  
     double maxx = max(a.x,b.x);  
     double maxy = max(a.y,b.y);  
     double minx = min(a.x,b.x); 
     double miny = min(a.y,b.y);  
     if( c.x >= minx && c.x <= maxx && c.y >= miny && c.y <= maxy )    
        return true;  
     return false;  
}  
bool segIntersect(Point p1,Point p2, Point p3, Point p4)  
{  
   double d1 = Direction(p3,p4,p1);  
   double d2 = Direction(p3,p4,p2);  
   double d3 = Direction(p1,p2,p3);  
   double d4 = Direction(p1,p2,p4);  
   if( d1 * d2 < eps && d3 * d4 < eps ) 
     return true;  
   if( d1 == 0.0 && onSegment(p3,p4,p1) ) 
     return true;  
   if( d2 == 0.0 && onSegment(p3,p4,p2) )  
     return true;  
   if( d3 == 0.0 && onSegment(p1,p2,p3) )  
     return true;  
   if( d4 == 0.0 && onSegment(p1,p2,p4) )  
     return true;  
   return false;  
}  
Line l[2010];  

int main()  
{  
  int n;  
  while( ~scanf("%d",&n) )  
  {  
     for(int i=0; i<n; i++)  
        scanf("%lf %lf %lf %lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y);  
     for(int i=0; i<n; i++)  
       for(int k=i+1; k<n; k++)  
          if( segIntersect(l[i].a,l[i].b,l[k].a,l[k].b))     
          {  
             printf("burned!\n");     
             goto end;  
          }  
     printf("ok!\n");  
     end:;  
  }  
  return 0;  
}  


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值