题意:
有n根木棍,每根的端点坐标分别是 px, py, qx, qy。
判断每对木棍是否相连,当他们之间有公共点时,就认为他们相连。
并且通过相连的木棍相连的木棍也是相连的。
解析:
线段相交的判定。
首先,模板中的线段相交是不判端点的,所以要加一个端点在直线上的判定;
然后,端点在直线上的判定这个函数是不判定两个端点是同一个端点的情况的,所以要加是否端点相等的判断。
最后,本身与本身是相连的,否则wa。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);
/
struct Point
{
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
bool cmp(Point A, Point B)
{
if (A.x == B.x)
return A.y < B.y;
return A.x < B.x;
}
typedef Point Vector;
Vector operator + (Vector A, Vector B)
{
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (Point A, Point B)
{
return Vector(A.x