Pick-up sticks

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1872    Accepted Submission(s): 706

Problem 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.
 
Source
 
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1142 1392 1148 1145 1155 

 
  计算几何,判断两线段相交
  题意是依次放置线段,相交即摞在上面,求最后在最上面的线段。
  急躁了,思路彻底乱了,最后还是参考了别人的代码。比赛的时候如果是这种状态,那绝对会拖累队友。
 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; struct Point{
double x,y;
};
struct Line{
Point p1,p2;
}l[];
double Max(double a,double b)
{
return a>b?a:b;
}
int MaxInt(int a,int b)
{
return a>b?a:b;
}
double Min(double a,double b)
{
return a<b?a:b;
}
double xmulti(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
bool inter(Line l1,Line l2)
{
if( Min(l2.p1.x,l2.p2.x)<=Max(l1.p1.x,l1.p2.x) &&
Min(l2.p1.y,l2.p2.y)<=Max(l1.p1.y,l1.p2.y) &&
Min(l1.p1.x,l1.p2.x)<=Max(l2.p1.x,l2.p2.x) &&
Min(l1.p1.y,l1.p2.y)<=Max(l2.p1.y,l2.p2.y) &&
xmulti(l1.p1,l2.p2,l2.p1)*xmulti(l1.p2,l2.p2,l2.p1)< &&
xmulti(l2.p1,l1.p2,l1.p1)*xmulti(l2.p2,l1.p2,l1.p1)< )
return true;
else
return false;
}
bool isv[];
int main()
{
int n;
while(cin>>n){
if(n==) break;
memset(isv,,sizeof(isv));
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&l[i].p1.x,&l[i].p1.y,&l[i].p2.x,&l[i].p2.y);
}
int num = n;
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
if(inter(l[i],l[j])){
isv[i] = ;
num--;
break;
} printf("Top sticks: ");
//输出所有存在的线段(即最顶上的线段)
for(int i=;i<=n;i++)
if(!isv[i]){ //是顶
num--;
if(num==)
printf("%d.\n",i);
else
printf("%d, ",i);
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 1147:Pick-up sticks(基本题,判断两线段相交)的更多相关文章

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

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

  2. 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 ...

  3. 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 ...

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

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

  5. HDU 1147 /// 判断两线段相交

    题目大意: 给定n条线段的端点 依次放上n条线段 判断最后在最上面(不被覆盖)的线段有哪些 到当前线段后 直接与之前保存的未被覆盖的线段判断是否相交就可以了 #include <cstdio&g ...

  6. TOJ1840: Jack Straws 判断两线段相交+并查集

    1840: Jack Straws  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Submit: 1 ...

  7. hdu 1086 You can Solve a Geometry Problem too [线段相交]

    题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...

  8. ACM1558两线段相交判断和并查集

    Segment set Problem Description A segment and all segments which are connected with it compose a seg ...

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

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

随机推荐

  1. Linux环境下的make和makefile详解

    无论是在Linux还是在Unix环境中,make都是一个非常重要的编译命令.不管是自己进行项目开发还是安装应用软件,我们都经常要用到make或make install.利用make工具,我们可以将大型 ...

  2. KeyboardJS - &quot;构建你的应用吧,我会处理按键&quot;

    KeyboardJS  - "构建你的应用吧,我会处理按键" 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业 ...

  3. solr 查询参数说明

    solr 查询参数说明

  4. ajax表单提交较慢原因的解决办法

    ajax提交表单时,发现过了好长时间才有反应.使用F12打开开发人员工具一看,发现提示“provisional headers are shown”. 百度了一下,才知道可能是ajax异步提交和for ...

  5. 使用TestFlight邀请外部人员測试APP

    怎样使用TestFlight邀请外部人员測试APP 详细过程例如以下: 1.在邀请測试人员的时候.按上线流程打包APP,提交. 2.提交审核,在邀请測试员的时候,你必须先提交审核,苹果会在大约2个工作 ...

  6. 1 - Reverse Integer

    Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Discuss: 1. ...

  7. ajax创建

    ajax对象创建和使用 //创建ajax对象 function createXMLhttp(){ var xmlhttp; if(window.XMLHttpRequest) {// code for ...

  8. SpringCloud-服务注册与发现

    这里我们会用到Spring Cloud Netflix,该项目是Spring Cloud的子项目之一,主要内容是对Netflix公司一系列开源产品的包装,它为Spring Boot应用提供了自配置的N ...

  9. php排序函数学习

    sort() 函数按升序对给定数组的值排序. 注释:本函数为数组中的单元赋予新的键名.原有的键名将被删除. 如果成功则返回 TRUE,否则返回 FALSE. <?php$my_array = a ...

  10. 在iOS App中增加完整的照片多选功能

    转自:http://blog.csdn.net/jasonblog/article/details/8141850 主要参考了ELCImagePickerController,不过由于UI展现上需要定 ...