Circuit Board(线段相交)


Link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=648


Circuit Board Time Limit: 2 Seconds       Memory Limit: 65536 KB

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!



AC code:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
struct point{
    double x;
    double y;
};
struct v{
    point s;
    point e;
}seg[2222];
double multi(point p1,point p2,point p0)
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int Acoross(struct v v1,struct v v2)
{
    if(max(v1.s.x,v1.e.x)>=min(v2.s.x,v2.e.x)&&
       max(v2.s.x,v2.e.x)>=min(v1.s.x,v1.e.x)&&
       max(v1.s.y,v1.e.y)>=min(v2.s.y,v2.e.y)&&
       multi(v2.s,v1.e,v1.s)*multi(v1.e,v2.e,v1.s)>=0&&
       multi(v1.s,v2.e,v2.s)*multi(v2.e,v1.e,v2.s)>=0)
        return 1;
    return 0;
}

int main()
{
   int n,i,j,fg;
   while(scanf("%d",&n)!=EOF)
   {
       for(i=1;i<=n;i++)
       {
           scanf("%lf%lf%lf%lf",&seg[i].s.x,&seg[i].s.y,&seg[i].e.x,&seg[i].e.y);
       }
       fg=0;
       for(i=1;i<=n;i++)
       {

           for(j=i+1;j<=n;j++)
           {

               if(Acoross(seg[i],seg[j]))
               {
                   fg=1;
                   break;
               }
           }
           if(fg)
            break;
       }
       if(fg==0)
        printf("ok!\n");
       else
        printf("burned!\n");
   }
    return 0;
}



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