Circuit Board

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=164

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!



YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
依旧线段相交,参照某人博客顺序,但没看代码;耶!耶!比上一个容易一点,用sort排序需要加头文件《algorithm》。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
	double x1,x2,y1,y2;
}g[2008];
int main()
{
	int i,j,k,m,n;
	double t,tt,ww,xx,yy;
	while(scanf("%d",&m)!=EOF)
	{
		//if(m==0)
		//break;
          for(i=0;i<m;i++)
          {
		     scanf("%lf%lf%lf%lf",&g[i].x1,&g[i].y1,&g[i].x2,&g[i].y2);
		     if(g[i].x1>g[i].x2)
		     {
     			t=g[i].x1;
     			g[i].x1=g[i].x2;
     			g[i].x2=t;
     			t=g[i].y1;
     			g[i].y1=g[i].y2;
     			g[i].y2=t;
     		}
          }
          //sort(g,g+m,cmp);
          int sum=0;
          for(i=0;i<m;i++)
          {
          	for(j=i+1;j<m;j++)
          	{
	          	if(((g[i].y2-g[i].y1)*(g[j].x2-g[j].x1)-(g[i].x2-g[i].x1)*(g[j].y2-g[j].y1))<1e-6)
	               	continue;
	          	xx=((g[j].y1*g[j].x2-g[j].y2*g[j].x1)*(g[i].x2-g[i].x1)-(g[i].y1*g[i].x2-g[i].y2*g[i].x1)*(g[j].x2-g[j].x1))/((g[i].y2-g[i].y1)*(g[j].x2-g[j].x1)-(g[j].y2-g[j].y1)*(g[i].x2-g[i].x1));
	          	yy=((g[i].y1*g[i].x2-g[i].y2*g[i].x1)*(g[j].y2-g[j].y1)-(g[j].y1*g[j].x2-g[j].y2*g[j].x1)*(g[i].y2-g[i].y1))/((g[j].x2-g[j].x1)*(g[i].y2-g[i].y1)-(g[i].x2-g[i].x1)*(g[j].y2-g[j].y1));
	          	if(xx>=g[i].x1&&xx<=g[i].x2&&xx>=g[j].x1&&xx<=g[j].x2)
	          	sum++;
	          }
          }   
          if(sum>0)
          printf("burned!\n");
          else
          printf("ok!\n");
	}
	return 0;
} 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值