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. 在Sharepoint中批量删除大量条目

    在Sharepoint开发中可能需要一次删除成百上千条记录,这时候如果轮询SPList.Items并直接调用该对象的删除方法来删除的话性能极差,会叫你崩溃. 下面介绍一个快速删除大量数据的方法: us ...

  2. python把汉字转换成拼音实现程序

    python把汉字转换成拼音实现程序 文章一个简洁干的汉字转拼音 程序,复制下载就可以直接使用,有需要的同学可以参考一下下. #coding:utf-8 #基于python2.6 table = 'a ...

  3. 【Tomcat】使用Eclipse运行Tomcat7源码

    1.搭建开发环境 a.下载好tomcat7源码包 b.安装好jdk7,及设置好环境变量 c.安装好ant,及设置好环境变量,用于预编译tocmat源码. d.以上步骤准备好我们就可以开始进入源码的预编 ...

  4. PhpStorm 10.0.1安装(win7-64位)

    软件下载地址 http://www.xiazaiba.com/html/25261.html#j_down_list 或者:http://pan.baidu.com/s/1brSA9C 密码:tpc7 ...

  5. java ee环境搭建

    1.安装java(tm)2 platform 2.下载安装Java EE SDK 版本:Java Platform,Enterprise Edition 7 SDK (with JDK 7u45) 下 ...

  6. Dokcer 组成原理简介

    首先来张图了解Docker的组成 重要 Docker在启动容器的时候,需要创建文件系统,为rootfs提供挂载点.最初Docker仅能在支持Aufs文件系统的Linux发行版上运行,但是由于Aufs未 ...

  7. ORA-20000: ORU-10027: buffer overflow, limit of 10000 bytes

        要用dbms_output.put_line来输出语句,遇到以下错误: ERROR 位于第 1 行: ORA-20000: ORU-10027: buffer overflow, limit ...

  8. (C#)Windows Shell 编程系列2 - 解释,从“桌面”开始展开

    原文 (C#)Windows Shell 编程系列2 - 解释,从“桌面”开始展开 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一篇:(C#)Windows Shell 编 ...

  9. Scrambled Polygon(凸多边形,斜率)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7805   Accepted: 3712 ...

  10. Memcached源代码分析 - Memcached源代码分析之消息回应(3)

    文章列表: <Memcached源代码分析 - Memcached源代码分析之基于Libevent的网络模型(1)> <Memcached源代码分析 - Memcached源代码分析 ...