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 ...
随机推荐
- Spring 学习笔记02
用spring实现一个论坛基本功能 1 运行环境 Linux:Ubun 14.04 64bit IDE:IntelliJ IDEA 14.03 JDK:1.7.40 MySQL:5.5.44 Tomc ...
- (原)python使用ctypes调用C/C++接口
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6135514.html 参考网址: https://docs.python.org/2/library/ ...
- MySQL 忘记密码后的重置操作
一.修改配置文件方式 1.关闭 MySQL linux: 1)service mysqld stop ...
- Symfony2之创建一个简单的web应用
Symfony2——创建bundle bundle就像插件或者一个功能齐全的应用,我们在应用层上开发的应用的所有代码,包括:PHP文件.配置文件.图片.css文件.js文件等都会包含在bu ...
- HTML&CSS基础学习笔记1.27-input提交数据
提交数据 我们在表单上填的信息很多情况下需要提交到后台. <input>的[type]属性值为“submit”时,表示提交表单数据.它在页面的表现形式也是个按钮,点击该按钮,表单数据将会提 ...
- 类和对象:面向对象编程 - 零基础入门学习Python037
类和对象:面向对象编程 让编程改变世界 Change the world by program 经过上节课的热身,相信大家对类和对象已经有了初步的认识,但似乎还是懵懵懂懂:好像面向对象编程很厉害,但不 ...
- js 发送ajax请求(XMLHttpRequest)
<!DOCTYPE html><html> <head> <title></title> <script type="tex ...
- 关于nginx架构探究(2)
nginx 数据结构 1.Hash table nginx 对虚拟主机的管理使用到了HASH数据结构,假设配置文件里有如下的配置. Server{ listen 192.168.0.1 server_ ...
- 在Visual Studio 2013中编译libssh2项目
一. 下载需要的外部包,并解压,下面给出的链接如果无法访问,就google搜索下载一下: •下载openssl •下载zlib 二.修改libssh2项目配置: 1.C/C++->Gene ...
- hdu4778:状压dp+博弈
题目大意: 有g种不同颜色的小球,b个袋子,每个袋子里面有若干个每种小球 两人轮流取袋子,当袋子里面的同色小球有s个时,会合并成一个魔法球,并被此次取袋子的人获得 成功获得魔法球的人可以再次取 求二者 ...