ZOJ 1648:Circuit Board __判断两线段相交

On the circuit board, there are lots of circuit paths. We know the basic constrain is that no two path cross each other, for otherwise the board will be burned.

Now given a circuit diagram, your task is to lookup if there are some crossed paths. If not find, print "ok!", otherwise "burned!" in one line.

A circuit path is defined as a line segment on a plane with two endpoints p1(x1,y1) and p2(x2,y2).

You may assume that no two paths will cross each other at any of their endpoints.


Input

The input consists of several test cases. For each case, the first line contains an integer n(<=2000), the number of paths, then followed by n lines each with four float numbers x1, y1, x2, y2.


Output

If there are two paths crossing each other, output "burned!" in one line; otherwise output "ok!" in one line.


Sample Input

1
0 0 1 1

2
0 0 1 1
0 1 1 0


Sample Output

ok!
burned!


//话说计算几何模板好多。需要明白嵌套。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define maxn 2005
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)

struct point
{
	double x,y;
};
struct line
{
	point sp,ep;
};
line a[maxn];

double x_multi(point p1,point p2,point p3)  //叉积
{
	return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}

bool Onsegment(point p1,point p2,point p3)  //快速排斥实验	
{
	double min_x=min(p1.x,p2.x);
	double min_y=min(p1.y,p2.y);
	double max_x=max(p1.x,p2.x);
	double max_y=max(p1.y,p2.y);
	if(p3.x>=min_x&&p3.x<=max_x&&p3.y>=min_y&&p3.y<=max_y)
		return true;
	return false;
}

bool Is_intersected(point p1,point p2,point p3,point p4)  
{
	double d1=x_multi(p1,p2,p3);
	double d2=x_multi(p1,p2,p4);
	double d3=x_multi(p3,p4,p1);
	double d4=x_multi(p3,p4,p2);
	if(d1*d2<0.0&&d3*d4<0.0)
		return true;
	if(d1==0.0&&Onsegment(p1,p2,p3))  //跨立实验
		return true;
	if(d2==0.0&&Onsegment(p1,p2,p4))
		return true;
	if(d3==0.0&&Onsegment(p3,p4,p1))
		return true;
	if(d4==0.0&&Onsegment(p3,p4,p2))
		return true;
	return false;
}

int main()
{
	int n,i,j;
	while(~scanf("%d",&n))
	{
		for(i=0;i<n;i++)
			scanf("%lf%lf%lf%lf",&a[i].sp.x,&a[i].sp.y,&a[i].ep.x,&a[i].ep.y);
		for(i=0;i<n;i++)
			for(j=i+1;j<n;j++)
			{
				if(Is_intersected(a[i].sp,a[i].ep,a[j].sp,a[j].ep))
				{
					puts("burned!");
					goto end;
				}
			}
		puts("ok!");
		end:;
	}	
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值