Pick-up sticks
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 11335   Accepted: 4250

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.
题解:这个题是让找出与其他直线不交或者在其他直线最上面的直线;
判断相交,两个直线的一个端点都要判断;
代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=<<;
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector;
Point dt[MAXN];
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
int main(){
int n,k,j;
while(scanf("%d",&n),n){
k=;
for(int i=;i<=n;i++)
scanf("%lf%lf%lf%lf",&dt[i].x,&dt[i].y,&dt[i+n].x,&dt[i+n].y);
printf("Top sticks: ");
for(int i=;i<n;i++){
for(j=i+;j<=n;j++){
if(Cross(dt[i]-dt[j],dt[i]-dt[j+n])*Cross(dt[i+n]-dt[j],dt[i+n]-dt[j+n])<=)
if(Cross(dt[j]-dt[i],dt[j]-dt[i+n])*Cross(dt[j+n]-dt[i],dt[j+n]-dt[i+n])<=)
break;
}
if(j==n+)printf("%d, ",i);
}
printf("%d.\n",n);
}
return ;
}

Pick-up sticks(判断两直线相交)的更多相关文章

  1. 【POJ 1269】判断两直线相交

    题 利用叉积解方程 #include <cstdio> #define MAX 1<<31 #define dd double int xmult(dd x1,dd y1,dd ...

  2. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. Intersecting Lines (计算几何基础+判断两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题面: Description We all know that a pair of distinct points on a ...

  4. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  5. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  6. You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...

  7. hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  8. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  9. 简单地判断判断两矩形相交/重叠 C#

    最近需要用到矩形相交算法的简单应用,所以特地拿一个很简单的算法出来供新手参考,为什么说是给新手的参考呢因为这个算法效率并不是很高,但是这个算法只有简简单单的三行.程序使用了两种方法来判断是否重叠/相交 ...

随机推荐

  1. window.showModalDialog刷新父窗口和本窗口的方法及注意

    window.showModalDialog刷新父窗口和本窗口的方法及注意:   一.刷新父窗口的方法:    A.使用window.returnValue给父窗口传值,然后根据值判断是否刷新. 在w ...

  2. 【转载】Qt中的QString,QByteArray,Qchar, char*

    先要说的是QString.         之所以把QString单独拿出来,是因为string是很常用的一个数据结构,甚至在很多语言中,比如JavaScript,都是把string作为一种同int等 ...

  3. UVa 11082 Matrix Decompressing(最大流)

    不想吐槽了..sample input 和sample output 完全对不上...调了一个晚上...不想说什么了... -------------------------------------- ...

  4. python实现进度条

    先说一下文本系统的控制符: \r: 将光标移动到当前行的首位而不换行: \n: 将光标移动到下一行,并不移动到首位: \r\n: 将光标移动到下一行首位. 环境: root@ubuntu16:/ale ...

  5. [LeetCode]题解(python):109-Convert Sorted List to Binary Search Tree

    题目来源: https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题意分析: 给定一个排好序的链表,将这个链 ...

  6. IOS 使用IOS6苹果地图

    IOS应用程序中使用Map Kit API开发地图应用程序.其核心是MKMapView类的使用.我们可以设置地图显示方式,控制地图,可以在地图上添加标注. 1.显示地图 在Map Kit API中显示 ...

  7. Java 多线程 socket 取款例子 runnable callable

    socket部分参考 http://blog.csdn.net/kongxx/article/details/7259465 取款部分参考 http://blog.csdn.net/dayday198 ...

  8. 一个最简的 USB Audio 示例

    经过了两三个月的痛苦,USB 协议栈的 Audio Device Class 框架已具雏形了,用了两三天时间,使用这个框架实战了一个基于新唐 M0 的最简单的 USB Audio 程序,可以作为 US ...

  9. Delphi函数指针的两种定义(对象方法存在一个隐藏参数self,所以不能相互赋值)

    delphi中经常见到以下两种定义 Type TMouseProc = procedure (X,Y:integer); TMouseEvent = procedure (X,Y:integer) o ...

  10. HDU 1584 蜘蛛牌

    题解:纸牌只能移到比其大一的纸牌上,所以移动方向是定的,那么,就只有选择移动先后的问题了,对于决定要移的纸牌,比如1,如果2,3,4都是visited的状态,那么1一定是要移动到5的,因为2,3,4一 ...