poj1127 Jack Straws 线段相交+并查集

博客探讨了如何使用线段相交算法和并查集数据结构来解决POJ1127问题,即判断平面上的n条线段之间是否存在直接或间接的连接关系。文章补充了线段相交模板中对共线但不相交情况的处理方法。
摘要由CSDN通过智能技术生成

平面上有n条线段,询问某两条线段是否直接或间接相连。

才发现以前写的线段相交模板中没有处理共线但不相交的情况,现在加上了。


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 10005
using namespace std;
typedef long long LL;
struct point
{
  LL x , y;
  point (LL x = 0 , LL y = 0): x(x) , y(y) {};
  void input() {cin >> x >> y;}
  bool operator < (const point& r) const{
    if (x == r.x)
      return y < r.y;
    return x < r.x;}
  bool operator == (const point& r) const{
    return x == r.x && y == r.y;
    }
};
point operator + (point a , point b) { return point(a.x + b.x , a.y + b.y);}
point operator - (point a , point b) { return point(a.x - b.x , a.y - b.y);}
LL Cross(point a , point b) {return a.x * b.y - a.y * b.x;}
double length(point a) {return
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值