链接: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!

。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/

模板题~~~

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#define eps 1e-6 struct point
{
double x,y;
}; struct beline
{
point a,b;
}; using namespace std; point p[]; bool dy(double x,double y)
{
return x > y+eps;
}
bool xy(double x,double y)
{
return x < y-eps;
}
bool xyd(double x,double y)
{
return x < y+eps;
}
bool dyd(double x,double y)
{
return x > y-eps;
}
double dd(double x,double y)
{
return fabs(x-y) < eps;
} double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} bool onSegment(point a,point b,point c)
{
double maxx=max(a.x,b.x);
double maxy=max(a.y,b.y);
double minx=min(a.x,b.x);
double miny=min(a.y,b.y);
if(dd(crossProduct(a,b,c),0.0)&&dyd(c.x,minx)&&xyd(c.x,maxx)
&&dyd(c.y,miny)&&xyd(c.y,maxy))
return true;
return false;
} bool segIntersect(point p1,point p2,point p3,point p4)
{
double d1 = crossProduct(p3,p4,p1);
double d2 = crossProduct(p3,p4,p2);
double d3 = crossProduct(p1,p2,p3);
double d4 = crossProduct(p1,p2,p4);
if(xy(d1*d2,0.0)&&xy(d3*d4,0.0))
return true;
if(dd(d1,0.0)&&onSegment(p3,p4,p1))
return true;
if(dd(d2,0.0)&&onSegment(p3,p4,p2))
return true;
if(dd(d3,0.0)&&onSegment(p1,p2,p3))
return true;
if(dd(d4,0.0)&&onSegment(p1,p2,p4))
return true;
return false;
} int main()
{
beline p[];
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&p[i].a.x,&p[i].a.y,&p[i].b.x,&p[i].b.y);
} if(n<=)
{
printf("ok!\n");
continue;
} bool flag=false;
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
{
if(segIntersect(p[i].a,p[i].b,p[j].a,p[j].b))
{
flag=true;
break;
}
}
}
if(flag)
{
printf("burned!\n");
}
else
{
printf("ok!\n");
}
}
return ;
}

zoj 1648 判断线段是否相交的更多相关文章

  1. Any Way You Slice It (向量旋转 以及 判断线段是否相交)(模板)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> # ...

  2. Jack Straws(判断线段是否相交 + 并查集)

    /** http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1840    题意:    判断线段 ...

  3. codeForce-589D Boulevard(判断线段是否相交)

    题目大意:n个人.一个区间.每个人都会在某个时间段内按相同的速度(所有人的速度都一样,都是1或-1)在他的区间内从一个端点走到另一个端点(只走一次).问每个人会与几个人碰面. 题目分析:将时间看成一个 ...

  4. HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )

    链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...

  5. 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)

    传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(s ...

  6. POJ 2653 Pick-up sticks (判断线段相交)

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10330   Accepted: 3833 D ...

  7. 判断线段相交(hdu1558 Segment set 线段相交+并查集)

    先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...

  8. POJ 2556 (判断线段相交 + 最短路)

    题目: 传送门 题意:在一个左小角坐标为(0, 0),右上角坐标为(10, 10)的房间里,有 n 堵墙,每堵墙都有两个门.每堵墙的输入方式为 x, y1, y2, y3, y4,x 是墙的横坐标,第 ...

  9. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

随机推荐

  1. java设置环境变量小工具

    unit MainUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Fo ...

  2. SslUtil

    package com.eaju.util; import java.io.OutputStreamWriter;import java.net.URL;import java.net.URLConn ...

  3. linux设备驱动归纳总结(四):5.多处理器下的竞态和并发【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-67673.html linux设备驱动归纳总结(四):5.多处理器下的竞态和并发 xxxxxxxxxx ...

  4. V4L2驱动程序框架架构【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11728809 1 V4L2简介 video4linux2(V4L2)是Linux内核中关 ...

  5. grads 用arcgis分析站点的网格

    第一步,用工具创建渔网(要素类) 第二步:将站点excel导入,生成点要素 站点excle,点击上面节点导出数据即可. 第三步,叠加在一起,找网格编号.

  6. editPlus,3.7V 注册码

    editPlus,3.7V 注册码: username:linzhihui password:5A2B6-69740-D9CDE-79702-C9CCD

  7. 阅读推荐——深入浅出Mesos

    深入浅出Mesos(一):为软件定义数据中心而生的操作系统http://www.infoq.com/cn/articles/analyse-mesos-part-01 深入浅出Mesos(二):Mes ...

  8. MySQL start and stop

    一.本文说明 本实验主要是演示MySQL的四种启动方式,附带停止的操作. 二.mysqld mysqld is the MySQL server   mysqld reads options from ...

  9. 提高PHP性能的实用方法+40个技巧优化您的PHP代码

    1.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的"函数" ...

  10. 5、XML(1)

    1 XML入门 1.1 引入 HTML: 负责网页的结构 CSS: 负责网页的样式(美观) Javascript: 负责在浏览器端与用户进行交互. 负责静态的网页制作的语言 HTML语言特点: 1)由 ...