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. GCC手册学习(序)

    已经是2014年的年末了,又快过了一年.今年,一定要认真把GCC再学习一遍,做好笔记. 总览 gcc [option|filename] ... g++ [option|filename] ...   ...

  2. word2vector 理解入门

    1.什么是word2vector? 我们先来看一个问题,假如有一个句子 " the dog bark at the mailman". 假如用向量来表示每个单词,我们最先想到的是用 ...

  3. Laravel 项目开发规范

    参考:https://fsdhub.com/books/laravel-specification

  4. freeswitch 音 视频 支持的编码

    FreeSWITCH 支持很多的语音编解码:[13] PCMU – G.711 µ-law PCMA – G.711 A-law G.722 G.722.1 G.722.1c G.726 G.726  ...

  5. ATITIT.翻译模块的设计与实现 api attilax 总结

    ATITIT.翻译模块的设计与实现 api attilax 总结 1. 翻译原理1 2. TMX格式是国际通用格式(xml)1 2.1. 方法/步骤2 3. TRADOS2 4. ATITIT.翻译软 ...

  6. 495. Implement Stack【easy】

    Implement a stack. You can use any data structure inside a stack except stack itself to implement it ...

  7. poj3253 优先队列

    Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...

  8. 跟着百度学PHP[14]-PDO的错误处理模式&PDO执行SQL

    我们在使用PDO去执行sql语句的时候并不会报错.如下案例所示: <?php try { //$pdo = new pdo("mysql:host=主机;port=端口;dbname= ...

  9. centos 6.5 安装mysql 5.7.21 community

    Step1: 检测系统是否自带安装mysql # yum list installed | grep mysql Step2: 删除系统自带的mysql及其依赖命令: # yum -y remove ...

  10. poj2391 Ombrophobic Bovines 拆点+二分法+最大流

    /** 题目:poj2391 Ombrophobic Bovines 链接:http://poj.org/problem?id=2391 题意:有n块区域,第i块区域有ai头奶牛,以及一个可以容纳bi ...