POJ - 2653 - Pick-up sticks 线段与线段相交
判断线段与线段相交
莫名其妙的数据量
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;
const double eps = 1e-;
int dcmp(double x)
{
return fabs(x) < eps ? : (x < ? - : );
}
struct Point
{
double x,y;
Point(double a = , double b = ) : x(a), y(b) {}
};
Point operator - (Point a, Point b)
{
return Point(a.x-b.x, a.y-b.y);
}
double Det(Point a, Point b)
{
return a.x * b.y - a.y * b.x;
}
double Dot(Point a, Point b)
{
return a.x*b.x + a.y*b.y;
}
bool OnSegment(Point p, Point a1, Point a2)
{
return dcmp(Det(a1 - p, a2 - p)) == && dcmp(Dot(a1 - p, a2 - p)) <= ;
}
bool SegCross(Point a1, Point a2, Point b1, Point b2)
{
double c1 = Det(a2 - a1, b1 - a1);
double c2 = Det(a2 - a1, b2 - a1);
double c3 = Det(b2 - b1, a1 - b1);
double c4 = Det(b2 - b1, a2 - b1);
if (dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ) return ;
else if (OnSegment(b1, a1, a2) ) return ;
else if (OnSegment(b2, a1, a2) ) return ;
else if (OnSegment(a1, b1, b2) ) return ;
else if (OnSegment(a2, b1, b2) ) return ;
else return ;
} struct Line
{
Point s,e;
Line() {}
Line(Point a,Point b) : s(a), e(b) {}
}l[];
int res[];
int main()
{
int n;
while (~scanf("%d", &n) && n)
{
for (int i = ; i <= n; i++){
scanf("%lf%lf%lf%lf", &l[i].e.x, &l[i].e.y, &l[i].s.x, &l[i].s.y);
}
int cnt = ;
for(int i = ; i <= n; i++)
{
bool flag = ;
for (int j = i+; j <= n; j++)
{
if(SegCross(l[i].e, l[i].s, l[j].e, l[j].s)){
flag = ; break;
}
}
if(flag) res[cnt++] = i;
} printf("Top sticks: ");
for (int i = ; i < cnt-; i++)
printf("%d, ", res[i]);
printf("%d.\n", res[cnt-]);
}
}
POJ - 2653 - Pick-up sticks 线段与线段相交的更多相关文章
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- POJ 2653 - Pick-up sticks - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K Description Stan has n s ...
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- poj 2653 线段与线段相交
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11884 Accepted: 4499 D ...
- 线段和矩形相交 POJ 1410
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...
- 判断线段和直线相交 POJ 3304
// 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio ...
- POJ 2828 Buy Tickets(排队问题,线段树应用)
POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意: 排队买票时候插队. 给出一些数对,分别代表某个人的想要插入的位 ...
- poj 1269 线段与线段相交
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13605 Accepted: 60 ...
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- 概率dp小结
好久之前学过,记得是一次亚洲区的前几天看了看概率dp,然后亚洲区就出了一道概率dp,当时虽然做上了,但是感觉有很多地方没懂,今天起早温习了一下,觉得很多地方茅塞顿开,果然学习的话早上效果最好了. 首先 ...
- uva 371 - Ackermann Functions
#include <cstdio> int main() { long int F, S, I, Count, Value, Max, J; while(scanf("%ld % ...
- XCode中使用SVN 教程
修改subversion.config方法: 可以直接在终端上输入:vi ~/.subversion/config来编辑. 也可以通过Finder搜索.subversion,点击下边的+号,进入高级搜 ...
- linux 搭建lamp环境
sudo apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql sudo chmod 777 /var/w ...
- 智能卡安全机制比较系列(三) MPCOS
MPCOS是金普斯早期推出的一款多应用支付芯片卡操作系统,支持ISO7816以及PCOS的数据格式和命令.MPCOS具有两级目录文件结构,即MF下可以有一级DF,每个DF下最多可创建63个EF. MP ...
- linux文件合并
第一:两个文件的交集,并集前提条件:每个文件中不得有重复行1. 取出两个文件的并集(重复的行只保留一份)2. 取出两个文件的交集(只留下同时存在于两个文件中的文件)3. 删除交集,留下其他的行1. c ...
- java常量设置的方式
我们在写java程序的时候,常常有常量设置,如: public interface Const { //性别的常量 public interface Sex{ public final int 男=1 ...
- jQuery 1.6+ 中attr()与prop() 区别
最近在写一个关于checkbox全选与取消全选的优化方法时,看到很多高手用到了.prop(). 于是在jquery的帮助文档查了一下,才知道这是在jquery 1.6.1中新加的方法,用来设置属性.但 ...
- 批量更新sql |批量update sql
图所示现需要批量更新table2表内字段Pwd更新userName对IP地址username与Ip对应关系table1所示 update table2 set pwd=table1.ip from t ...
- Firefox历史版本下载
http://ftp.mozilla.org/pub/firefox/releases/ http://ftp.mozilla.org/pub/firefox/releases/47.0.1/