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 ...
随机推荐
- effective_c++条款20,用pass-by-reference-to-const替换pass-by-value
pass-by-value void f(A a); 1)导致复制是浪费资源 2)多态是导致对象切割 所以我们使用 void f(const A& a) 上面的话针对class,不针对基本类型 ...
- (转)OS X 升級後 MacPorts 重新安裝筆記
原地址:http://blog.lyhdev.com/2012/07/os-x-macports.html Mac OS X 10.8 Mountain Lion 正式發佈,而且祭出台幣 $590 元 ...
- q3 bsp随笔(2)
看完了q3的port生成,以及pvs的生成 做个记录 由于q3 bsp树生成时,将场景中所有的brush平面都参与, 所以就可用bsp树的分割平面来切分port port从根节点开始,初始windin ...
- win7 删除服务
以管理员身份运行命令行工具. 输入 sc delete "服务名" 如若服务名有特殊字符需要加引号. sc dekete apache_pn
- C/C++ char和int的区别
字符字面值一般是用一对单引号来表示.char类型一般就是用字符字面值来初始化.赋值.由于char类型的是单字节长度,当给char类型的变量用字符字面值赋值时,当单引号里面的内容超过一个字节时,系统会自 ...
- F#(1)
如果你也会C#,那不妨了解下F#(1):F# 数据类型 简单介绍 F#(与C#一样,念作“F Sharp”)是一种基于.Net框架的强类型.静态类型的函数式编程语言.可以说C#是一门包含函数式编程 ...
- Scala学习文档-访问修饰符
在scala里,对保护成员的访问比Java严格.Scala中,保护成员只在定义了成员的类的子类中可以访问,而Java中,还允许在同一个包的其他类中访问. package p1 { class FCla ...
- Google Analytics:为链接点击设定事件追踪的方法
在 Google Analytics 中,可以使用 Event Tracking 功能跟踪自定义的事件.但是,如果你要跟踪的是一个链接点击,那么单纯这样写则很有可能导致漏掉许多事件: <a hr ...
- iOS 9的 Universal Links 通用链接使用
前段时间和朋友(@品味生活)一起搞 iOS9的通用链接,我主要做了前面官方文档翻译工作,后面的一些东西都是他在搞,整理也是他整理的. 他的博客原文地址:http://pinwei.blog.51cto ...
- C语言里面关于数组的一个容易忽视的小细节
ginobili@VM_44_28_sles10sp1:~/code> cat test3.cpp #include <stdio.h> int main(){ char a[5] ...