POJ_2653_Pick-up sticks_判断线段相交

Description

Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.

Input

Input consists of a number of cases. The data for each case start with 1 <= n <= 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is ended by the case with n=0. This case should not be processed.

Output

For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown.

The picture to the right below illustrates the first case from input.

Sample Input

5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0

Sample Output

Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.

斯坦有各种长度的n条。他在地板上随意地扔了一个。在完成投掷后,斯坦试图找到最上面的棍子,那就是这些棍子,这样就没有棍子在上面了。
斯坦注意到,最后一根投掷棒总是在上面,但他想知道上面所有的棍子。斯坦棒非常非常薄,以至于它们的厚度可以被忽略。 暴力可过的一道题。直接枚举所有的所有的线段判断能不能被后面的覆盖即可。
然后判断线段相交用四次叉积判断即可。 代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef double f2;
#define N 100050
#define eps 1e-6
bool vis[N];
int ans[N],n;
struct Point {
f2 x,y;
Point() {}
Point(f2 x_,f2 y_) :
x(x_),y(y_) {}
Point operator + (const Point &p) const {return Point(x+p.x,y+p.y);}
Point operator - (const Point &p) const {return Point(x-p.x,y-p.y);}
Point operator * (f2 rate) const {return Point(x*rate,y*rate);}
};
f2 dot(const Point &p1,const Point &p2) {return p1.x*p2.x+p1.y*p2.y;}
f2 cross(const Point &p1,const Point &p2) {return p1.x*p2.y-p1.y*p2.x;}
f2 FABS(f2 x) {return x>0?x:-x;}
struct Line {
Point p,v;
Line() {}
Line(const Point &p_,const Point &v_) :
p(p_),v(v_) {}
};
Line a[N];
f2 turn(const Point &p1,const Point &p2,const Point &p3) {
return cross(p3-p1,p2-p1);
}
bool judge(const Line &l1,const Line &l2) {
if(turn(l1.p,l1.v,l2.p)*turn(l1.p,l1.v,l2.v)>0) return 0;
if(turn(l2.p,l2.v,l1.p)*turn(l2.p,l2.v,l1.v)>0) return 0;
return 1;
}
void init() {
memset(vis,0,sizeof(vis)); ans[0]=0;
}
void solve() {
init();
int i,j;
f2 x,y,z,w;
int fir=0;
for(i=1;i<=n;i++) {
scanf("%lf%lf%lf%lf",&a[i].p.x,&a[i].p.y,&a[i].v.x,&a[i].v.y);
}
printf("Top sticks:");
for(i=1;i<=n;i++) {
int flg=0;
for(j=i+1;j<=n;j++) {
if(judge(a[i],a[j])) {
flg=1; break;
}
}
if(!flg) {
if(!fir) {
fir=1;
}else printf(",");
printf(" %d",i);
}
}
puts(".");
}
int main() {
while(scanf("%d",&n)&&n) {
solve();
}
}

												

POJ_2653_Pick-up sticks_判断线段相交的更多相关文章

  1. 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)

    传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(s ...

  2. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

  3. POJ 2653 Pick-up sticks(判断线段相交)

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7699   Accepted: 2843 De ...

  4. 判断线段相交(hdu1558 Segment set 线段相交+并查集)

    先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...

  5. hdu 1086(判断线段相交)

    传送门:You can Solve a Geometry Problem too 题意:给n条线段,判断相交的点数. 分析:判断线段相交模板题,快速排斥实验原理就是每条线段代表的向量和该线段的一个端点 ...

  6. POJ_1066_Treasure Hunt_判断线段相交

    POJ_1066_Treasure Hunt_判断线段相交 Description Archeologists from the Antiquities and Curios Museum (ACM) ...

  7. POJ_1556_The Doors_判断线段相交+最短路

    POJ_1556_The Doors_判断线段相交+最短路 Description You are to find the length of the shortest path through a ...

  8. POJ 1066--Treasure Hunt(判断线段相交)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7857   Accepted: 3247 Des ...

  9. POJ2653 Pick-up sticks 判断线段相交

    POJ2653 判断线段相交的方法 先判断直线是否相交 再判断点是否在线段上 复杂度是常数的 题目保证最后答案小于1000 故从后往前尝试用后面的线段 "压"前面的线段 排除不可能 ...

随机推荐

  1. 【React入门实例(运行于浏览器duan)】

    一.HTML模板 二.ReactDOM.render() ReactDOM.render是React的最基本方法,用于将模板转换为HTML语言,并插入指定的DOM节点. ReactReactDOM.r ...

  2. Centos 7 卸载自带的openjdk

    [root@localhost ~]# rpm -qa|grep jdk java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64 java-1.7.0- ...

  3. 微信小程序弹出和隐藏遮罩层动画以及五星评分

    参考源码: http://www.see-source.com/weixinwidget/detail.html?wid=82 https://blog.csdn.net/pcaxb/article/ ...

  4. linux下安装xhprof

    https://jingyan.baidu.com/article/a24b33cd7ee1d519ff002b6d.html

  5. .net core使用Ku.Core.Extensions.Layui实现layui表单渲染

    演示网站地址:http://layui.kulend.com/项目地址:https://github.com/kulend/Ku.Core.Extensions/tree/master/Ku.Core ...

  6. Python 描述符是什么?以及如何实现

    先看一个例子,@property.被@property修饰的成员函数,将变为一个描述符.这是最简单的创建描述符的方式. class Foo: @property def attr(self): pri ...

  7. [Kali_Metasploit]db_connect创建连接时无法连接的解决方案

    问题1复现路径: postgresql selected, no connection 第一步: db_connect postgres:toor@127.0.0.1/msfbook 连接成功不需要进 ...

  8. 敏捷(Agile)——“说三道四”

    可以这么理解:一种以人为本.团队合作.快速响应变化和可工作的软件作为宗旨的开发方法.亦可理解为在一个高度协作的环境中,不断地使用反馈进行自我调整和完善,持续交付用户想要的软件的过程.敏捷开发提倡通过多 ...

  9. Tomcat配置与优化(内存、并发、管理)与性能监控

    原文链接:http://blog.csdn.net/xyang81/article/details/51530979 一.JVM内存配置优化 在开发当中,当一个项目比较大时,依赖的jar包通常比较多, ...

  10. java中判断文件及所在文件夹是否存在

    File file=new File(filePath);if (file.exists()) {}else { File fileParent =new File(file.getParent()) ...