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<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct Point
{
double x,y;
}a[2005][2];
int n;
double mult(Point a, Point b, Point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
} //aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false
bool intersect(Point aa, Point bb, Point cc, Point dd)
{
if ( max(aa.x, bb.x)<min(cc.x, dd.x) )
{
return false;
}
if ( max(aa.y, bb.y)<min(cc.y, dd.y) )
{
return false;
}
if ( max(cc.x, dd.x)<min(aa.x, bb.x) )
{
return false;
}
if ( max(cc.y, dd.y)<min(aa.y, bb.y) )
{
return false;
}
if ( mult(cc, bb, aa)*mult(bb, dd, aa)<0 )
{
return false;
}
if ( mult(aa, dd, cc)*mult(dd, bb, cc)<0 )
{
return false;
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y);
bool tag=true;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(intersect(a[i][0],a[i][1],a[j][0],a[j][1]))
{tag=false;break;}
}
if(!tag)
break;
}
if(!tag)
printf("burned!\n");
else
printf("ok!\n");
}
return 0;
}

ZOJ 1648 Circuit Board(计算几何)的更多相关文章

  1. zoj 1648 Circuit Board

    题目:意思就是推断给定的几条线段是否有相交的. 方法:模版吧,有空在来细细学习. 代码: #include <iostream> #include <cstdio> using ...

  2. ZOJ1648 Circuit Board 2017-04-18 20:31 34人阅读 评论(0) 收藏

    Circuit Board Time Limit: 2 Seconds      Memory Limit: 65536 KB On the circuit board, there are lots ...

  3. Printed Circuit Board (board)

    Printed Circuit Board (board) 题目描述 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出 ...

  4. zoj 1648 判断线段是否相交

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=648 Circuit Board Time Limit: 2 Second ...

  5. ZOJ 1696 Viva Confetti 计算几何

    计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...

  6. NEFU 506&&ZOJ 3353 Chess Board (四种构造的高斯消元)

    题目链接 题意:有四种翻转方式,问是否能使得所有棋子都变为0,求最小步数. 题解:依次构造枚举求出最小值即可. #include <iostream> #include <cstdi ...

  7. ZOJ1648 Circuit Board(线段相交)

    裸的判断线段相交

  8. ZOJ 2675 Little Mammoth(计算几何)

    圆形与矩形截面的面积 三角仍然可以做到这一点 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  9. bzoj2856: [ceoi2012]Printed Circuit Board

    Description 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出所有满足要求的顶点编号. Input 第一行一 ...

随机推荐

  1. C#定时任务的偷懒实现

    通常会有些定时任务的工作,例如每分钟统计一下xxx用户的xxx数量 或者 定时拉取下数据 之类的任务. 通常要实现定时调度功能和控制线程是否可以并发执行. 所以通常一个简单的小项目搞成大项目,但是使用 ...

  2. HIVE的transform函数的使用

    Hive的TRANSFORM关键字提供了在SQL中调用自写脚本的功能,适合实现Hive中没有的功能又不想写UDF的情况.例如,按日期统计每天出现的uid数,通常用如下的SQL SELECT date, ...

  3. 何为优秀的机器学习特征 zz

    提供好的特征是机器学习任务中最重要的工作,那么何为优秀的机器学习特征?以及如何高效地组合这些特征? 以二分类问题为例,好的特征具有很好的区分性.例如学习任务是区分两种不同类型的狗:灰猎犬(Greyho ...

  4. Java内存分析工具jmap

    1. jmap 1.1 概述 JVM Memory Map命令用于生成heap dump文件,如果不使用这个命令,还可以使用-XX:+HeapDumpOnOutOfMemoryError参数来让虚拟机 ...

  5. Effective Java-第4章

    第4章 类和接口 类和接口是Java程序设计语言的核心,它们也是Java语言的基本抽象单元.Java语言提供了许多强大的基本元素,供程序员用来设计类和接口. 13. 使类和成员的可访问性最小化 要区别 ...

  6. html页面中js判断浏览器是否是IE浏览器及IE浏览器版本

    HTML里: HTML代码中,在编写网页代码时,各种浏览器的兼容性是个必须考虑的问题,有些时候无法找到适合所有浏览器的写法,就只能写根据浏览器种类区别的代码,这时就要用到判断代码了.在HTML代码中, ...

  7. sqlmap里如何添加字典

    在sqlmap的目录下有那么一个目录.即"TXT"目录. 该目录下是放字典的. 我在日一个站的时候没有破解出表明.然后不小心下载到了数据库. sqlmap无法猜出表是啥.ps:ac ...

  8. Android 开发 -------- 自己定义View 画 五子棋

    自己定义View  实现 五子棋 配图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG92ZV9KYXZjX3lvdQ==/font/5a6L5L2T ...

  9. Unix系统编程(四)creat系统调用

    我好疑惑啊,creat系统调用为啥没有以e结尾呢?搞得我每次都怀疑我敲错了. 在早期的UNIX实现中,open只有两个参数,无法创建新文件,而是使用creat系统调用创建并打开一个新文件. int c ...

  10. 页面表单里的图片上传ENCTYPE="multipart/form-data"

    ENCTYPE="multipart/form-data"用于表单里有图片上传. <form action="<%=basePath %>asyUplo ...