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!

——————————————————————————————————————

题目的意思是给出n条线段,问是否有线段相交

两两之间暴力判,判可以用模板



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f struct Point
{
double x;
double y;
};
typedef struct Point point;
struct line
{
point p1,p2;
}; double multi(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool is(point s1,point e1,point s2,point e2)
{
return (max(s1.x,e1.x)>=min(s2.x,e2.x))&&
(max(s2.x,e2.x)>=min(s1.x,e1.x))&&
(max(s1.y,e1.y)>=min(s2.y,e2.y))&&
(max(s2.y,e2.y)>=min(s1.y,e1.y))&&
(multi(s1,s2,e1)*multi(s1,e1,e2)>0)&&
(multi(s2,s1,e2)*multi(s2,e2,e1)>0);
} int main()
{
int n;
line L[2005];
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
{
scanf("%lf%lf%lf%lf",&L[i].p1.x,&L[i].p1.y,&L[i].p2.x,&L[i].p2.y);
}
int flag=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(i==j)
continue;
if(is(L[i].p1,L[i].p2,L[j].p1,L[j].p2))
{
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("burned!\n");
else
printf("ok!\n");
}
return 0;
}


Author: ZHOU, Feng

Source: ZOJ Monthly, September 2003

ZOJ1648 Circuit Board 2017-04-18 20:31 34人阅读 评论(0) 收藏的更多相关文章

  1. hadoop调优之一:概述 分类: A1_HADOOP B3_LINUX 2015-03-13 20:51 395人阅读 评论(0) 收藏

    hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...

  2. Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏

    Self Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22101   Accepted: 12429 De ...

  3. 高质量C++C编程指南笔记 标签: c++笔记 2015-11-22 20:59 179人阅读 评论(0) 收藏

    1.  在多重循环中,如果有可能,应当将最长的循环放在最内层,最短的循环放在最外层,以减少 CPU 跨切循环层的次数. 2.  如果循环体内存在逻辑判断,并且循环次数很大,宜将逻辑判断移到循环体的外面 ...

  4. Codeforces812B Sagheer, the Hausmeister 2017-06-02 20:47 85人阅读 评论(0) 收藏

    B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. UI基础:UIView(window,frame,UIColor,CGPoint,alpha,CGRect等) 分类: iOS学习-UI 2015-06-30 20:01 119人阅读 评论(0) 收藏

    UIView 视图类,视图都是UIView或者UIView子类 UIWindow 窗口类,用于展示视图,视图一定要添加window才能显示 注意:一般来说,一个应用只有一个window 创建一个UIW ...

  6. OC基础:OC 基本数据类型与对象之间的转换方法 分类: ios学习 OC 2015-06-18 20:01 11人阅读 评论(0) 收藏

    1.Foundation框架中提供了很多的集合类如:NSArray,NSMutableArray,NSSet,NSMutableSet,NSDictionary,NSMutableDictionary ...

  7. ZOJ2748 Free Kick 2017-04-18 20:40 40人阅读 评论(0) 收藏

    Free Kick Time Limit: 2 Seconds      Memory Limit: 65536 KB In a soccer game, a direct free kick is ...

  8. ZSTU4269 买iphone 2017-03-22 14:31 73人阅读 评论(0) 收藏

    4269: 买iphone Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 1710  Solved: 316 Description 自从上次仓鼠中了 ...

  9. 各种排序算法的分析及java实现 分类: B10_计算机基础 2015-02-03 20:09 186人阅读 评论(0) 收藏

    转载自:http://www.cnblogs.com/liuling/p/2013-7-24-01.html 另可参考:http://gengning938.blog.163.com/blog/sta ...

随机推荐

  1. Java 获取字符串长度 length()

    Java 手册 实例: public class Length { public static void main(String[] args) { String str = "hgdfas ...

  2. 北京师范大学第十六届程序设计竞赛决赛-重现赛-B题

    一.题目链接 https://www.nowcoder.com/acm/contest/117/B 二.题意 给定一组序列$a_1,a_2,\cdots,a_n$,表示初始序列$b_1,b_2,\cd ...

  3. PackedSyncPtr

    folly/PackedSyncPtr.h A highly specialized data structure consisting of a pointer, a 1-bit spin lock ...

  4. AWT,Swing,RCP 开发

    http://www.blogjava.net/youxia/category/17374.html

  5. 常用的ubantu操作命令

    Ubuntu软件操作的相关命令 sudo apt-get update 更新源 sudo apt-get install package 安装包 sudo apt-get remove package ...

  6. Input设置只读属性

    input设置为只读一般用于查看详情: 格式为: (1)单纯的input框 <div class="form-group"> <label for="c ...

  7. OpenCL 三种内存对象的使用

    ▶ 包括带有 CL_MEM_READ_ONLY,CL_MEM_WRITE_ONLY,CL_MEM_READ_WRITE 标识的显示拷贝(函数 clEnqueueWriteBuffer 和 clEnqu ...

  8. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  9. (网页的缓存控制)HTML配置no-cache(备忘) “Cache-control”常见的取值

    HTML配置no-cache(备忘) No-cache配置 html表头如下 <meta http-equiv="Content-Type" content="te ...

  10. Redis 基础操作

    [Redis 基础操作] 1.ECHO message. Returns message. 2.PHING Returns PONG if no argument is provided, other ...