ZOJ 1648 Circuit Board(计算几何)
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(计算几何)的更多相关文章
- zoj 1648 Circuit Board
题目:意思就是推断给定的几条线段是否有相交的. 方法:模版吧,有空在来细细学习. 代码: #include <iostream> #include <cstdio> using ...
- 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 ...
- Printed Circuit Board (board)
Printed Circuit Board (board) 题目描述 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出 ...
- zoj 1648 判断线段是否相交
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=648 Circuit Board Time Limit: 2 Second ...
- ZOJ 1696 Viva Confetti 计算几何
计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...
- NEFU 506&&ZOJ 3353 Chess Board (四种构造的高斯消元)
题目链接 题意:有四种翻转方式,问是否能使得所有棋子都变为0,求最小步数. 题解:依次构造枚举求出最小值即可. #include <iostream> #include <cstdi ...
- ZOJ1648 Circuit Board(线段相交)
裸的判断线段相交
- ZOJ 2675 Little Mammoth(计算几何)
圆形与矩形截面的面积 三角仍然可以做到这一点 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- bzoj2856: [ceoi2012]Printed Circuit Board
Description 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出所有满足要求的顶点编号. Input 第一行一 ...
随机推荐
- PHP保留2位小数、格式化小数、浮点数
JS保留两位小数例子 四舍五入使用函数 toFixed() [javascript] <html> <head> </head> <script> va ...
- 使用NoSQL Manager for MongoDBclient连接mongodb
1.安装NoSQL Manager for MongoDB 下载地址:http://www.mongodbmanager.com/download 2.打开client,选server-new mon ...
- PHP 时间与日期
PHP提供了大量的内置函数,使开发者在时间的处理上游刃有余,大大提高了工作效率. 介绍一些常见的PHP日期和时间函数以及日期和时间的处理. 经常使用的日期和时间处理函数 函 数 说 明 checkd ...
- Effective Java-第4章
第4章 类和接口 类和接口是Java程序设计语言的核心,它们也是Java语言的基本抽象单元.Java语言提供了许多强大的基本元素,供程序员用来设计类和接口. 13. 使类和成员的可访问性最小化 要区别 ...
- [Android]Volley源代码分析(叁)Network
假设各位看官细致看过我之前的文章,实际上Network这块的仅仅是点小功能的补充.我们来看下NetworkDispatcher的核心处理逻辑: <span style="font-si ...
- 李洪强iOS开发之iOS工具收集
李洪强iOS开发之iOS工具收集 项目 简述 日期 我是怎么慢慢变懒的 : Jenkins + 蒲公英 使用Jenkins + 蒲公英使得项目打包给测试人员自动化,大大节省了劳动力 2015.04.1 ...
- 关于EasyUI的Layout总结
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.layout以html标签方式建立的 <div id="content" region="center&q ...
- IEnumerable扩展
void Main() { // This uses a custom 'Pair' extension method, defined below. Customers .Select (c =&g ...
- 质问微软 WP8.1开发HTTPS 真费劲
本人用C#多年,WPF2年,一直想做点应用为WP生态贡献一点力量,最近终于有机会接触了 家里的本子是2年前的低压I3,不支持虚拟化,一直没有真机.最近同事妈妈换下来一个820给我拿来做开发用,非常感谢 ...
- 目录视图摘要视图订阅 基于Extjs开发不允许为空的文本框提示及相应的验证错误提示(转)
原文地址:http://blog.csdn.net/kunoy/article/details/8007585 本文主要解决问题: 1.区分哪些文本框不允许为空,很多网站都采用在文本框后加*号,ext ...