POJ - 1127 Jack Straws 线段相交+Floyd

题目链接:https://vjudge.net/problem/POJ-1127

题目大意:

给出n条线段,线段相交即连通,判断任意两条线段是否连通

题目解析:

首先根据线段相交得出一个邻接矩阵,
然后根据Floyd算法,得出一个更直接的直接能看出两条线段是否相连的邻接矩阵

也可以用BFS

AC代码:

#include
#include
#include
#include
#include
using namespace std;
struct Point {
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}
};

Point p[200];

typedef Point Vector;
Vector operator + (Vector A,Vector B){
	return Vector(A.x+B.x,A.y+B.y);
} 
Vector operator - (Vector A,Vector B){
	return Vector(A.x-B.x,A.y-B.y);
} 
Vector operator * (Vector A,double p){
	return Vector(A.x*p,A.y*p);
} 
Vector operator / (Vector A,double p){
	return Vector(A.x/p,A.y/p);
} 

bool operator < (const Point &a,const Point &b){
	if(a.x==b.x){
		return a.y=min(S2.y, E2.y) &&
        min(S1.x, E1.x)<=max(S2.x, E2.x) &&
        max(S1.x, E1.x)>=min(S2.x, E2.x)){
        return true;
    }
    return false;
}

bool SegmentProperIntersection(Point A1, Point A2, Point B1, Point B2) {
	double T1 = Cross(A1, A2, B1);
	double T2 = Cross(A1, A2, B2);
    double T3 = Cross(B1, B2, A1);
    double T4 = Cross(B1, B2, A2);
	if(((T1*T2)>0)||((T3*T4)>0)){// 一条线段的两个端点在另一条线段的同侧,不相交。(可能需要额外处理以防止乘法溢出,视具体情况而定。)
        return false;
    }else if(T1==0&&T2==0){             // 两条线段共线,利用快速排斥实验进一步判断。此时必有 T3 == 0 && T4 == 0。
		return rectsIntersect(A1, A2, B1, B2);
    } else {                                    // 其它情况,两条线段相交。
        return true;
    }
}

//https://www.cnblogs.com/kane1990/p/5742830.html


/*
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){
	double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-b1);
	double c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
	if(!sgn(c1)||!sgn(c2)||!sgn(c3)||!sgn(c4)){
		bool f1=OnSegment(b1,a1,a2);
		bool f2=OnSegment(b2,a1,a2);
		bool f3=OnSegment(a1,b1,b2);
		bool f4=OnSegment(a2,b1,b2);
		bool f=(f1|f2|f3|f4);
		return f;
	} 
	return (sgn(c1)*sgn(c2)<0&&sgn(c3)*sgn(c4)<0);
} 
*/

struct node{
	int x,y;
};
node no[200];
int mp[200][200];
int n;

int vis[200]; 

int BFS(node a){
	memset(vis,0,sizeof(vis));
	int S=a.x;
	int E=a.y;
	queue q;
	q.push(S);
	vis[S]=1;
//	cout<<"**"<>n;
		if(n==0){
			break;
		}
		for(int i=1;i<=n;i++){
			Point a,b;
			cin>>a.x>>a.y>>b.x>>b.y;
			L[i].v=a,L[i].p=b;
		}
		int x,y;
		int cnt=0;
//		cout<<"***********"<>x>>y&&x!=0&&y!=0){
//			cout<

 

你可能感兴趣的:(计算几何)