POJ 3304 Segments

叉积+暴力

注意变量前后要保持一致,以为这个问题wa了很多发

#include
#include
using namespace std;

#define maxn 105
#define precision 1e-10

int n;

struct Point{
	double x;
	double y;
}; 
Point Left[maxn],Right[maxn];
double det(double x1,double y1,double x2,double y2){
	return x1*y2-x2*y1;
}
double cross(Point a,Point b,Point c){
	return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
int check(Point a,Point b){
	if(abs(a.x-b.x)precision){
			return 0;
		}
	}
	return 1;
}

int main(){
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		bool flag=0;
		if(n<3){
			flag=1;
		}
		for(int i=1;i<=n;i++){
			cin>>Left[i].x>>Left[i].y;
			cin>>Right[i].x>>Right[i].y;
		}
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(flag){
					break;
				}
				if(check(Left[i],Right[j])){
					flag=1;
				}else if(check(Left[i],Left[j])){
					flag=1;
				}else if(check(Right[i],Right[j])){
					flag=1;
				}else if(check(Right[i],Left[j])){
					flag=1;
				}
			}
			if(flag){
				break;
			}
		}
		if(flag){
			cout<<"Yes!"<

 

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