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 ...
随机推荐
- poj3685 二分套二分
F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS Memory Limit:65536KB 64bit ...
- RMQ问题
关于RMQ的问题我就直接截取刘汝佳的<算法竞赛训练指南>上的解释了
- C++基于模板顺序表的实现(带排序)
说明:代码是可以运行的,但是发表在博客上后复制到编译器里面报N多错误,找了半天原因是网页里面生成了一些空白字符,这些字符编译器无法识别. 因此使用了2种插入格式插入代码. 第二个带注释解释的代码不可复 ...
- quartz spring 时间配置
关于时间配置, 1前面带0和不带0的区别是??? (开始时间,带0以整点整分整秒开始,不带的以启动时间定时循环??) 比如 0 7/37 * * * ? 表示每个小时的第7分钟开始执行,然后隔三 ...
- C程序设计语言练习题1-4
练习1-4 编写一个程序打印摄氏温度转换为相应华氏温度的转换表. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() // 定义名为main的 ...
- HTML5实现的视频播放器01
HTML5实现的视频播放器 什么是hivideo? 最近一段时间在使用PhoneGap开发一个App应用,App需要播放视频,本想直接使用html5的video,但使用它在全屏播放时不支持横屏播放 ...
- [转]IBInspectable / IBDesignable
原文:http://www.cocoachina.com/ios/20150227/11202.html 无论陈词滥调多少次,比起一个需要我们记住并且输入什么的界面来说,如果替换成我们能够看见并可控制 ...
- PHP 之mysql空字符串问题
有一张user表如下所示:字段name不能为空. CREATE TABLE `user` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `a ...
- HTML5的local storage存储的数据到底存到哪去了
原文地址:http://zhidao.baidu.com/link?url=m6p5MLv0R46lDCd_Vnrry4XOMbdCwgV5fzs3tj5Jeyht1nPkAZ9OrO23njYBY1 ...
- Manacher算法----最长回文子串
题目描述 给定一个字符串,求它的最长回文子串的长度. 分析与解法 最容易想到的办法是枚举所有的子串,分别判断其是否为回文.这个思路初看起来是正确的,但却做了很多无用功,如果一个长的子串包含另一个短一些 ...