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. JS基础速成(三)- DOM(文件对象模型)

    .t1 { background-color: #ff8080; width: 1100px; height: 40px } 一.DOM树的基本结构 DOM节点分为三大类:元素节点(标签节点),属性节 ...

  2. JDK内置工具之一——JMap(java memory map)

    1.介绍 打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量). 可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.使用方法 j ...

  3. jquery.js

    /*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license //@ sourceMappingUR ...

  4. 在Windows上安装Git

    实话实说,Windows是最烂的开发平台,如果不是开发Windows游戏或者在IE里调试页面,一般不推荐用Windows.不过,既然已经上了微软的贼船,也是有办法安装Git的. Windows下要使用 ...

  5. CSS position 笔记+实验

    目录: 1.static 2.relative 3.absolute 4.fixed 5.实验:static, relative, absolute中,父元素-子元素高度关系 6.z-index 7. ...

  6. Angular5的new feature

    https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced Version 5.0.0 of Angular ...

  7. Future与Promise

    https://code.csdn.NET/DOC_Scala/chinese_scala_offical_document/file/Futures-and-Promises-cn.md#ancho ...

  8. Floyd 算法求多源最短路径

    Floyd算法: Floyd算法用来找出每对顶点之间的最短距离,它对图的要求是,既可以是无向图也可以是有向图,边权可以为负,但是不能存在负环(可根据最小环的正负来判定). 基本算法: Floyd算法基 ...

  9. Oracle知识梳理(三)操作篇:SQL基础操作汇总

    Oracle知识梳理(三)操作篇:SQL基础操作汇总 一.表操作 1.表的创建(CREATE TABLE): 基本语句格式:       CREATE TABLE  table_name ( col_ ...

  10. ES 在聚合结果中进行过滤

    ES查询中,先聚合,在聚合结果中进行过滤 { "size": 0, "aggs": { "terms": { "terms&quo ...